- 64E606C3F54EE3585735C6B2050A7C2262AF782632635616EB363A9DD6A48E4C43AFEAD5370DA655644B4194E2F974D936AF97F4425C568EC382E23D747D40F3
+ EC569AE6EE3890AD5ACEF443CEAC290FE43C084515FF09F60A65AD07DFC147BD858B2E2AEA5F0C687673F6EDE25AC6EA8EEF145CEDAC6359F227D2225D808965
eucrypt/smg_keccak/smg_oaep.ads
(14 . 12)(14 . 33)
374 OAEP_LENGTH_OCTETS : constant := 512;
375 OAEP_HALF_OCTETS : constant := OAEP_LENGTH_OCTETS / 2;
376 TMSR : constant String := "TMSR-RSA";
377 MAX_LEN_MSG : constant := OAEP_HALF_OCTETS - TMSR'Length - 3;
378 MAX_LEN_MSG : constant Natural := OAEP_HALF_OCTETS - TMSR'Length - 3;
379 pragma Export( C, MAX_LEN_MSG, "max_len_msg"); -- to be accessed from rsa.c
380
381 -- subtypes used by the OAEP encrypt/decrypt
382 subtype OAEP_Block is String( 1 .. OAEP_LENGTH_OCTETS );
383 subtype OAEP_HALF is String( 1 .. OAEP_HALF_OCTETS );
384
385 -- copy from Ada String to C char array and back, octet by octet
386
387 -- This copies first Len characters from A to the first Len positions in S
388 -- NB: this does NOT allocate /check memory!
389 -- Caller has to ensure that:
390 -- S has space for at least Len characters
391 -- A has at least Len characters
392 procedure Char_Array_To_String( A : in Interfaces.C.char_array;
393 Len : in Natural;
394 S : out String);
395
396 -- This copies first Len characters from S to the first Len positions in A
397 -- NB: there are NO checks or memory allocations here!
398 -- Caller has to make sure that:
399 -- S'Length >= Len
400 -- A has allocated space for at least Len characters
401 procedure String_To_Char_Array( S : in String;
402 Len : in Natural;
403 A : out Interfaces.C.char_array);
404
405 -- padding & formatting of maximum 1960 bits of the given String
406 -- uses TMSR's OAEP schema:
407 -- 1.format M00 as: [random octet][sz1][sz2]"TMSR-RSA"[random]*Message
(32 . 9)(53 . 25)
409 -- NB: the Entropy parameter should be random octets from which this method
410 -- will use as many as required for the OAEP encryption of given Msg
411 -- NB: at MOST MAX_LEN_MSG octets of Msg! (Msg at most 1960 bits)
412 procedure OAEP_Encrypt( Msg : in String;
413 Entropy : in OAEP_Block;
414 Output : out OAEP_Block);
415 procedure OAEP_Encrypt( Msg : in String;
416 Entropy : in OAEP_Block;
417 Output : out OAEP_Block);
418
419
420 -- wrapper of oaep_encrypt for direct use from C
421 -- NB: caller HAS TO provide the length of the Message (parameter LenMsg)
422 -- NB: caller HAS TO provide the length of the Entropy (parameter LenEnt)
423 -- NB: caller HAS TO provide the allocated space for result (LenEncr)
424 -- NB: LenEncr HAS TO be at least OAEP_LENGTH_OCTETS!
425 -- NB: LenEnt HAS TO be at least OAEP_LENGTH_OCTETS or this will FAIL!
426 procedure OAEP_Encrypt_C( Msg : in Interfaces.C.char_array;
427 MsgLen : in Interfaces.C.size_t;
428 Entropy : in Interfaces.C.char_array;
429 EntLen : in Interfaces.C.size_t;
430 Encr : out Interfaces.C.char_array;
431 EncrLen : in Interfaces.C.size_t;
432 Success : out Interfaces.C.Int);
433 pragma Export( C, OAEP_Encrypt_C, "oaep_encrypt_c" );
434
435 -- This is the opposite of OAEP_Encrypt above.
436 -- @param Encr - an OAEP block previously obtained from OAEP_Encrypt
(47 . 6)(84 . 14)
438 Output : out OAEP_HALF;
439 Success : out Boolean);
440
441 -- wrapper for use from C
442 procedure oaep_decrypt_c( Encr : in Interfaces.C.Char_Array;
443 EncrLen : in Interfaces.C.Int;
444 Decr : out Interfaces.C.Char_Array;
445 DecrLen : in out Interfaces.C.Int;
446 Success : out Interfaces.C.Int);
447 pragma Export( C, oaep_decrypt_c, "oaep_decrypt_c");
448
449 -- helper method, xor on strings
450 -- NB: only Output'Length bits will be considered from S1 and S2
451 -- NB: caller is responsible for S1 and S2 being long enough!
(73 . 20)(118 . 17)
453 Output : out String;
454 Block_Len : in Keccak_Rate := Default_Bitrate);
455
456 -- wrapper for calling from C
457 -- wrapper for calling Keccak hashing from C, with DEFAULT bitrate
458 -- @param Input the input string, as array of characters (C style)
459 -- @param LenIn the length of the input string (as number of BITS)
460 -- @param LenOut the desired number of bits to be returned as output
461 -- @param Block_Len the bitrate used by the Keccak sponge (number of BITS)
462 -- @return an array of characters with first LenOut bits set to Keccak output
463
464 -- @param LenIn the length of the input string (as number of OCTETS)
465 -- @param LenOut the desired number of OCTETS to be returned as output
466 -- @param Output array of at least LenOut characters; will contain the hash
467 -- NB: caller HAS TO provide the length of the Input (parameter LenIn)
468 -- NB: caller HAS TO provide the length of the Output (parameter LenOut)
469 function Hash( Input : Interfaces.C.Char_Array;
470 LenIn : Interfaces.C.size_t;
471 LenOut : Interfaces.C.size_t;
472 Block_Len : Interfaces.C.int := Default_Bitrate)
473 return Interfaces.C.Char_Array;
474 procedure Hash( Input : in Interfaces.C.Char_Array;
475 LenIn : in Interfaces.C.size_t;
476 LenOut : in Interfaces.C.size_t;
477 Output : out Interfaces.C.Char_Array);
478 pragma Export( C, Hash, "hash" );
479
480 end SMG_OAEP;