File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,32 @@ String ECCX08Class::serialNumber()
91
91
return result;
92
92
}
93
93
94
+ long ECCX08Class::random (long max)
95
+ {
96
+ return random (0 , max);
97
+ }
98
+
99
+ long ECCX08Class::random (long min, long max)
100
+ {
101
+ if (min >= max)
102
+ {
103
+ return min;
104
+ }
105
+
106
+ long diff = max - min;
107
+
108
+ long r;
109
+ random ((byte*)&r, sizeof (r));
110
+
111
+ if (r < 0 ) {
112
+ r = -r;
113
+ }
114
+
115
+ r = (r % diff);
116
+
117
+ return (r + min);
118
+ }
119
+
94
120
int ECCX08Class::random (byte data[], size_t length)
95
121
{
96
122
if (!wakeup ()) {
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ class ECCX08Class
34
34
35
35
String serialNumber ();
36
36
37
+ long random (long max);
38
+ long random (long min, long max);
37
39
int random (byte data[], size_t length);
38
40
39
41
int generatePrivateKey (int slot, byte publicKey[]);
You can’t perform that action at this time.
0 commit comments