@@ -48,7 +48,7 @@ typedef struct {
4848 @param src The number to copy from
4949 @return CRYPT_OK on success
5050 */
51- int (* init_copy )(void * * dst , void * src );
51+ int (* init_copy )(void * * dst , const void * src );
5252
5353 /** deinit
5454 @param a The number to free
@@ -63,14 +63,14 @@ typedef struct {
6363 @param dst The destination
6464 @return CRYPT_OK on success
6565 */
66- int (* neg )(void * src , void * dst );
66+ int (* neg )(const void * src , void * dst );
6767
6868 /** copy
6969 @param src The number to copy from
7070 @param dst The number to write to
7171 @return CRYPT_OK on success
7272 */
73- int (* copy )(void * src , void * dst );
73+ int (* copy )(const void * src , void * dst );
7474
7575/* ---- trivial low level functions ---- */
7676
@@ -86,20 +86,20 @@ typedef struct {
8686 only fetches up to bits_per_digit from the number
8787 @return The lower bits_per_digit of the integer (unsigned)
8888 */
89- unsigned long (* get_int )(void * a );
89+ unsigned long (* get_int )(const void * a );
9090
9191 /** get digit n
9292 @param a The number to read from
9393 @param n The number of the digit to fetch
9494 @return The bits_per_digit sized n'th digit of a
9595 */
96- ltc_mp_digit (* get_digit )(void * a , int n );
96+ ltc_mp_digit (* get_digit )(const void * a , int n );
9797
9898 /** Get the number of digits that represent the number
9999 @param a The number to count
100100 @return The number of digits used to represent the number
101101 */
102- int (* get_digit_count )(void * a );
102+ int (* get_digit_count )(const void * a );
103103
104104 /** compare two integers
105105 @param a The left side integer
@@ -108,7 +108,7 @@ typedef struct {
108108 LTC_MP_GT if a > b and
109109 LTC_MP_EQ otherwise. (signed comparison)
110110 */
111- int (* compare )(void * a , void * b );
111+ int (* compare )(const void * a , const void * b );
112112
113113 /** compare against int
114114 @param a The left side integer
@@ -117,19 +117,19 @@ typedef struct {
117117 LTC_MP_GT if a > b and
118118 LTC_MP_EQ otherwise. (signed comparison)
119119 */
120- int (* compare_d )(void * a , ltc_mp_digit n );
120+ int (* compare_d )(const void * a , ltc_mp_digit n );
121121
122122 /** Count the number of bits used to represent the integer
123123 @param a The integer to count
124124 @return The number of bits required to represent the integer
125125 */
126- int (* count_bits )(void * a );
126+ int (* count_bits )(const void * a );
127127
128128 /** Count the number of LSB bits which are zero
129129 @param a The integer to count
130130 @return The number of contiguous zero LSB bits
131131 */
132- int (* count_lsb_bits )(void * a );
132+ int (* count_lsb_bits )(const void * a );
133133
134134 /** Compute a power of two
135135 @param a The integer to store the power in
@@ -154,30 +154,30 @@ typedef struct {
154154 @param radix The radix the integer is to be represented in (2-64)
155155 @return CRYPT_OK on success
156156 */
157- int (* write_radix )(void * a , char * str , int radix );
157+ int (* write_radix )(const void * a , char * str , int radix );
158158
159159 /** get size as unsigned char string
160160 @param a The integer to get the size (when stored in array of octets)
161161 @return The length of the integer in octets
162162 */
163- unsigned long (* unsigned_size )(void * a );
163+ unsigned long (* unsigned_size )(const void * a );
164164
165165 /** store an integer as an array of octets
166166 @param src The integer to store
167167 @param dst The buffer to store the integer in
168168 @return CRYPT_OK on success
169169 */
170- int (* unsigned_write )(void * src , unsigned char * dst );
170+ int (* unsigned_write )(const void * src , unsigned char * dst );
171171
172172 /** read an array of octets and store as integer
173173 @param dst The integer to load
174174 @param src The array of octets
175175 @param len The number of octets
176176 @return CRYPT_OK on success
177177 */
178- int (* unsigned_read )( void * dst ,
179- unsigned char * src ,
180- unsigned long len );
178+ int (* unsigned_read )( void * dst ,
179+ const unsigned char * src ,
180+ unsigned long len );
181181
182182/* ---- basic math ---- */
183183
@@ -187,7 +187,7 @@ typedef struct {
187187 @param c The destination of "a + b"
188188 @return CRYPT_OK on success
189189 */
190- int (* add )(void * a , void * b , void * c );
190+ int (* add )(const void * a , const void * b , void * c );
191191
192192 /** add two integers
193193 @param a The first source integer
@@ -196,15 +196,15 @@ typedef struct {
196196 @param c The destination of "a + b"
197197 @return CRYPT_OK on success
198198 */
199- int (* addi )(void * a , ltc_mp_digit b , void * c );
199+ int (* addi )(const void * a , ltc_mp_digit b , void * c );
200200
201201 /** subtract two integers
202202 @param a The first source integer
203203 @param b The second source integer
204204 @param c The destination of "a - b"
205205 @return CRYPT_OK on success
206206 */
207- int (* sub )(void * a , void * b , void * c );
207+ int (* sub )(const void * a , const void * b , void * c );
208208
209209 /** subtract two integers
210210 @param a The first source integer
@@ -213,7 +213,7 @@ typedef struct {
213213 @param c The destination of "a - b"
214214 @return CRYPT_OK on success
215215 */
216- int (* subi )(void * a , ltc_mp_digit b , void * c );
216+ int (* subi )(const void * a , ltc_mp_digit b , void * c );
217217
218218 /** multiply two integers
219219 @param a The first source integer
@@ -222,7 +222,7 @@ typedef struct {
222222 @param c The destination of "a * b"
223223 @return CRYPT_OK on success
224224 */
225- int (* mul )(void * a , void * b , void * c );
225+ int (* mul )(const void * a , const void * b , void * c );
226226
227227 /** multiply two integers
228228 @param a The first source integer
@@ -231,22 +231,22 @@ typedef struct {
231231 @param c The destination of "a * b"
232232 @return CRYPT_OK on success
233233 */
234- int (* muli )(void * a , ltc_mp_digit b , void * c );
234+ int (* muli )(const void * a , ltc_mp_digit b , void * c );
235235
236236 /** Square an integer
237237 @param a The integer to square
238238 @param b The destination
239239 @return CRYPT_OK on success
240240 */
241- int (* sqr )(void * a , void * b );
241+ int (* sqr )(const void * a , void * b );
242242
243243 /** Square root (mod prime)
244244 @param a The integer to compute square root mod prime from
245245 @param b The prime
246246 @param c The destination
247247 @return CRYPT_OK on success
248248 */
249- int (* sqrtmod_prime )(void * a , void * b , void * c );
249+ int (* sqrtmod_prime )(const void * a , const void * b , void * c );
250250
251251 /** Divide an integer
252252 @param a The dividend
@@ -255,38 +255,38 @@ typedef struct {
255255 @param d The remainder (can be NULL to signify don't care)
256256 @return CRYPT_OK on success
257257 */
258- int (* mpdiv )(void * a , void * b , void * c , void * d );
258+ int (* mpdiv )(const void * a , const void * b , void * c , void * d );
259259
260260 /** divide by two
261261 @param a The integer to divide (shift right)
262262 @param b The destination
263263 @return CRYPT_OK on success
264264 */
265- int (* div_2 )(void * a , void * b );
265+ int (* div_2 )(const void * a , void * b );
266266
267267 /** Get remainder (small value)
268268 @param a The integer to reduce
269269 @param b The modulus (upto bits_per_digit in length)
270270 @param c The destination for the residue
271271 @return CRYPT_OK on success
272272 */
273- int (* modi )(void * a , ltc_mp_digit b , ltc_mp_digit * c );
273+ int (* modi )(const void * a , ltc_mp_digit b , ltc_mp_digit * c );
274274
275275 /** gcd
276276 @param a The first integer
277277 @param b The second integer
278278 @param c The destination for (a, b)
279279 @return CRYPT_OK on success
280280 */
281- int (* gcd )(void * a , void * b , void * c );
281+ int (* gcd )(const void * a , const void * b , void * c );
282282
283283 /** lcm
284284 @param a The first integer
285285 @param b The second integer
286286 @param c The destination for [a, b]
287287 @return CRYPT_OK on success
288288 */
289- int (* lcm )(void * a , void * b , void * c );
289+ int (* lcm )(const void * a , const void * b , void * c );
290290
291291 /** Modular multiplication
292292 @param a The first source
@@ -295,23 +295,23 @@ typedef struct {
295295 @param d The destination (a*b mod c)
296296 @return CRYPT_OK on success
297297 */
298- int (* mulmod )(void * a , void * b , void * c , void * d );
298+ int (* mulmod )(const void * a , const void * b , const void * c , void * d );
299299
300300 /** Modular squaring
301301 @param a The first source
302302 @param b The modulus
303303 @param c The destination (a*a mod b)
304304 @return CRYPT_OK on success
305305 */
306- int (* sqrmod )(void * a , void * b , void * c );
306+ int (* sqrmod )(const void * a , const void * b , void * c );
307307
308308 /** Modular inversion
309309 @param a The value to invert
310310 @param b The modulus
311311 @param c The destination (1/a mod b)
312312 @return CRYPT_OK on success
313313 */
314- int (* invmod )(void * , void * , void * );
314+ int (* invmod )(const void * a , const void * b , void * c );
315315
316316/* ---- reduction ---- */
317317
@@ -320,22 +320,22 @@ typedef struct {
320320 @param b The destination for the reduction digit
321321 @return CRYPT_OK on success
322322 */
323- int (* montgomery_setup )(void * a , void * * b );
323+ int (* montgomery_setup )(const void * a , void * * b );
324324
325325 /** get normalization value
326326 @param a The destination for the normalization value
327327 @param b The modulus
328328 @return CRYPT_OK on success
329329 */
330- int (* montgomery_normalization )(void * a , void * b );
330+ int (* montgomery_normalization )(void * a , const void * b );
331331
332332 /** reduce a number
333333 @param a The number [and dest] to reduce
334334 @param b The modulus
335335 @param c The value "b" from montgomery_setup()
336336 @return CRYPT_OK on success
337337 */
338- int (* montgomery_reduce )(void * a , void * b , void * c );
338+ int (* montgomery_reduce )(void * a , const void * b , void * c );
339339
340340 /** clean up (frees memory)
341341 @param a The value "b" from montgomery_setup()
@@ -352,15 +352,15 @@ typedef struct {
352352 @param d The destination
353353 @return CRYPT_OK on success
354354 */
355- int (* exptmod )(void * a , void * b , void * c , void * d );
355+ int (* exptmod )(const void * a , const void * b , const void * c , void * d );
356356
357357 /** Primality testing
358358 @param a The integer to test
359359 @param b The number of Miller-Rabin tests that shall be executed
360360 @param c The destination of the result (FP_YES if prime)
361361 @return CRYPT_OK on success
362362 */
363- int (* isprime )(void * a , int b , int * c );
363+ int (* isprime )(const void * a , int b , int * c );
364364
365365/* ---- (optional) ecc point math ---- */
366366
@@ -374,11 +374,11 @@ typedef struct {
374374 (can be ignored if you work in affine only)
375375 @return CRYPT_OK on success
376376 */
377- int (* ecc_ptmul )( void * k ,
377+ int (* ecc_ptmul )( const void * k ,
378378 const ecc_point * G ,
379379 ecc_point * R ,
380- void * a ,
381- void * modulus ,
380+ const void * a ,
381+ const void * modulus ,
382382 int map );
383383
384384 /** ECC GF(p) point addition
@@ -393,8 +393,8 @@ typedef struct {
393393 int (* ecc_ptadd )(const ecc_point * P ,
394394 const ecc_point * Q ,
395395 ecc_point * R ,
396- void * ma ,
397- void * modulus ,
396+ const void * ma ,
397+ const void * modulus ,
398398 void * mp );
399399
400400 /** ECC GF(p) point double
@@ -407,8 +407,8 @@ typedef struct {
407407 */
408408 int (* ecc_ptdbl )(const ecc_point * P ,
409409 ecc_point * R ,
410- void * ma ,
411- void * modulus ,
410+ const void * ma ,
411+ const void * modulus ,
412412 void * mp );
413413
414414 /** ECC mapping from projective to affine,
@@ -421,7 +421,7 @@ typedef struct {
421421 ecc_point only has three integers (x,y,z) so if
422422 you use a different mapping you have to make it fit.
423423 */
424- int (* ecc_map )(ecc_point * P , void * modulus , void * mp );
424+ int (* ecc_map )(ecc_point * P , const void * modulus , void * mp );
425425
426426 /** Computes kA*A + kB*B = C using Shamir's Trick
427427 @param A First point to multiply
@@ -436,8 +436,8 @@ typedef struct {
436436 int (* ecc_mul2add )(const ecc_point * A , void * kA ,
437437 const ecc_point * B , void * kB ,
438438 ecc_point * C ,
439- void * ma ,
440- void * modulus );
439+ const void * ma ,
440+ const void * modulus );
441441
442442/* ---- (optional) rsa optimized math (for internal CRT) ---- */
443443
@@ -479,7 +479,7 @@ typedef struct {
479479 @param d The destination (a + b mod c)
480480 @return CRYPT_OK on success
481481 */
482- int (* addmod )(void * a , void * b , void * c , void * d );
482+ int (* addmod )(const void * a , const void * b , const void * c , void * d );
483483
484484 /** Modular substraction
485485 @param a The first source
@@ -488,7 +488,7 @@ typedef struct {
488488 @param d The destination (a - b mod c)
489489 @return CRYPT_OK on success
490490 */
491- int (* submod )(void * a , void * b , void * c , void * d );
491+ int (* submod )(const void * a , const void * b , const void * c , void * d );
492492
493493/* ---- misc stuff ---- */
494494
0 commit comments