-
+ C24569926E5388672B1AF9E79B01B55902F2176DE3F2887C978327871820CF1EE19BC9B0B52BA614A90FF197FAC4A91C0975133EC55B38F362BE48E3DEACE1B3
smg_comms/c_wrappers/c_wrappers.h
(0 . 0)(1 . 105)
264 //Wrapper methods for C implementations of RSA and MPI.
265 //To be used / called from Ada so that the C part remains well separated and
266 // can therefore be swapped easily at a later stage for something sane.
267 //S.MG, 2018
268
269 #include "mpi.h"
270
271 //Comparison of 2 arrays of octets interpreted as MPIs.
272 //This method creates 2 MPIs out of the given arrays of octes and then
273 // calls the mpi_cmp method from mpi/mpi-cmp.c, returning its result.
274 // ************************************************************************
275 // ***NB: Make SURE that a and b have indeed allocated at least len_a and
276 // ***** len_b octets respectively! NO CHECKS PERFORMED BY THIS METHOD!
277 // ************************************************************************
278 //@param a An array of octets representing the first MPI.
279 //@param len_a The length of the first array (number of octets).
280 //@param b An array of octets representing the second MPI.
281 //@param len_b The length of the second array (number of octets).
282 //@return 0 when a=b, -1 when a<b, 1 when a>b
283 int mpi_cmp_octets(char *a, unsigned int len_a, char *b, unsigned int len_b);
284
285 //Encryption of given octets with public RSA key: n and e given as octets too.
286 // ************************************************************************
287 // ***Length of output is KEY_LENGTH_OCTETS.
288 // ***NB: Make SURE that out, input, n and e have enough space allocated!!
289 // ***NB: NO MEMORY ALLOCATED for its parameters by this method and
290 // ***** NO CHECKS PERFORMED BY THIS METHOD!
291 // ************************************************************************
292 //@param out Pointer to ALREADY ALLOCATED space for the encrypted data.
293 //@param len_out Length of the allocated space for out (in octets).
294 //@param input Pointer to the data to be encrypted.
295 //@param len_input Length of the allocated space for input (in octets).
296 //@param n Pointer to the public RSA modulus to use for encryption.
297 //@param len_n Length of n (in octets).
298 //@param e Pointer to the public RSA exponent to use for encryption.
299 //@param len_e Length of e (in octets).
300 //@return The actual length of the output i.e. number of chars written to out.
301 int public_rsa_octets( char *out , unsigned int len_out,
302 char *input, unsigned int len_input,
303 char *n , unsigned int len_n,
304 char *e , unsigned int len_e);
305
306
307 //Encryption of given octets with *private* RSA key given as octets.
308 // ************************************************************************
309 // ***Length of output is KEY_LENGTH_OCTETS.
310 // ***NB: Make SURE that ALL pointers have enough space allocated!!
311 // ***NB: NO MEMORY ALLOCATED for its parameters by this method and
312 // ***** NO CHECKS PERFORMED BY THIS METHOD!
313 // ************************************************************************
314 //@param out Pointer to ALREADY ALLOCATED space for the encrypted data.
315 //@param len_out Length of the allocated space for out (in octets).
316 //@param input Pointer to the data to be encrypted.
317 //@param len_input Length of the allocated space for input (in octets).
318 //@param n Pointer to the public RSA modulus of the given key.
319 //@param len_n Length of n (in octets).
320 //@param e Pointer to the public RSA exponent of the given key.
321 //@param len_e Length of e (in octets).
322 //@param d Pointer to the private RSA exponent of the given key.
323 //@param len_d Length of d (in octets).
324 //@param p Pointer to the prime p of the given key.
325 //@param len_p Length of p (in octets).
326 //@param q Pointer to the prime q of the given key.
327 //@param len_q Length of q (in octets).
328 //@param u Pointer to the inverse of p mod q for the given key.
329 //@param len_u Length of u (in octets).
330 //@return The actual length of the output i.e. number of chars written to out.
331 int private_rsa_octets( char *out, unsigned int len_out,
332 char *input, unsigned int len_input,
333 char *n , unsigned int len_n,
334 char *e , unsigned int len_e,
335 char *d , unsigned int len_d,
336 char *p , unsigned int len_p,
337 char *q , unsigned int len_q,
338 char *u , unsigned int len_u);
339
340 //Generates a new RSA key and stores its components at the specified locations.
341 //@param n Pointer to the public RSA modulus of the given key.
342 //@param len_n Length of n (in octets).
343 //@param e Pointer to the public RSA exponent of the given key.
344 //@param len_e Length of e (in octets).
345 //@param d Pointer to the private RSA exponent of the given key.
346 //@param len_d Length of d (in octets).
347 //@param p Pointer to the prime p of the given key.
348 //@param len_p Length of p (in octets).
349 //@param q Pointer to the prime q of the given key.
350 //@param len_q Length of q (in octets).
351 //@param u Pointer to the inverse of p mod q for the given key.
352 //@param len_u Length of u (in octets).
353 void gen_rsa_octets( char *n, unsigned int *len_n,
354 char *e, unsigned int *len_e,
355 char *d, unsigned int *len_d,
356 char *p, unsigned int *len_p,
357 char *q, unsigned int *len_q,
358 char *u, unsigned int *len_u);
359
360 //Copies the buffer of m to the location to which out points.
361 //*****************************************************************
362 //*** This method does NOT allocate memory for out!
363 //*** NB: caller should allocate enough memory!
364 //*****************************************************************
365 //@param out pointer to allocated memory where to copy the MPI's octets
366 //@param len_out size of out; will be replaced by actual number of octets copied
367 //@param m The MPI whose octets are to be retrieved
368 void mpi_to_octets( char *out, unsigned int *len_out, MPI m);