@@ -877,15 +877,24 @@ int crypto_sign_open(uint8_t *m, size_t *mlen, const uint8_t *sm, size_t smlen,
877877 * - mld_hash_alg_t hashAlg: hash algorithm enumeration
878878 *
879879 * Returns 0 if hash algorithm is supported and -1 otherwise.
880- * Currently only SHAKE-256 is supported.
880+ * Currently SHAKE-128 and SHAKE-256 are supported.
881881 **************************************************/
882882static int prehash_message (uint8_t * out , size_t * oid_ph_len , const uint8_t * m ,
883883 size_t mlen , mld_hash_alg_t hashAlg )
884884{
885- /* OIDs for supported hash functions - currently only SHAKE-256 is implemented
886- */
885+ /* OIDs for supported hash functions */
886+ const uint8_t shake_128_oid [11 ] = {0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
887+ 0x65 , 0x03 , 0x04 , 0x02 , 0x0B };
887888 const uint8_t shake_256_oid [11 ] = {0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
888889 0x65 , 0x03 , 0x04 , 0x02 , 0x0C };
890+ const uint8_t sha3_256_oid [11 ] = {0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
891+ 0x65 , 0x03 , 0x04 , 0x02 , 0x08 };
892+ const uint8_t sha3_224_oid [11 ] = {0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
893+ 0x65 , 0x03 , 0x04 , 0x02 , 0x07 };
894+ const uint8_t sha3_384_oid [11 ] = {0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
895+ 0x65 , 0x03 , 0x04 , 0x02 , 0x09 };
896+ const uint8_t sha3_512_oid [11 ] = {0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 ,
897+ 0x65 , 0x03 , 0x04 , 0x02 , 0x0A };
889898
890899 /* OIDs for hash functions to be added:
891900 const uint8_t sha2_224_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
@@ -900,38 +909,53 @@ static int prehash_message(uint8_t *out, size_t *oid_ph_len, const uint8_t *m,
900909 0x65, 0x03, 0x04, 0x02, 0x05};
901910 const uint8_t sha2_512_256_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
902911 0x65, 0x03, 0x04, 0x02, 0x06};
903- const uint8_t sha3_224_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
904- 0x65, 0x03, 0x04, 0x02, 0x07};
905- const uint8_t sha3_256_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
906- 0x65, 0x03, 0x04, 0x02, 0x08};
907- const uint8_t sha3_384_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
908- 0x65, 0x03, 0x04, 0x02, 0x09};
909- const uint8_t sha3_512_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
910- 0x65, 0x03, 0x04, 0x02, 0x0A};
911- const uint8_t shake_128_oid[11] = {0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
912- 0x65, 0x03, 0x04, 0x02, 0x0B};
913912 */
914913
915914 switch (hashAlg )
916915 {
916+ case MLD_SHAKE_128 :
917+ mld_memcpy (out , shake_128_oid , 11 );
918+ mld_shake128 (out + 11 , 32 , m , mlen );
919+ * oid_ph_len = 11 + 32 ;
920+ return 0 ;
921+
917922 case MLD_SHAKE_256 :
918923 mld_memcpy (out , shake_256_oid , 11 );
919924 mld_shake256 (out + 11 , 64 , m , mlen );
920925 * oid_ph_len = 11 + 64 ;
921926 return 0 ;
922927
928+ case MLD_SHA3_256 :
929+ mld_memcpy (out , sha3_256_oid , 11 );
930+ mld_sha3_256 (out + 11 , m , mlen );
931+ * oid_ph_len = 11 + 32 ;
932+ return 0 ;
933+
934+ case MLD_SHA3_224 :
935+ mld_memcpy (out , sha3_224_oid , 11 );
936+ mld_sha3_224 (out + 11 , m , mlen );
937+ * oid_ph_len = 11 + 28 ;
938+ return 0 ;
939+
940+ case MLD_SHA3_384 :
941+ mld_memcpy (out , sha3_384_oid , 11 );
942+ mld_sha3_384 (out + 11 , m , mlen );
943+ * oid_ph_len = 11 + 48 ;
944+ return 0 ;
945+
946+ case MLD_SHA3_512 :
947+ mld_memcpy (out , sha3_512_oid , 11 );
948+ mld_sha3_512 (out + 11 , m , mlen );
949+ * oid_ph_len = 11 + 64 ;
950+ return 0 ;
951+
923952 /* Other hash algorithms not yet supported */
924953 case MLD_SHA2_224 :
925954 case MLD_SHA2_256 :
926955 case MLD_SHA2_384 :
927956 case MLD_SHA2_512 :
928957 case MLD_SHA2_512_224 :
929958 case MLD_SHA2_512_256 :
930- case MLD_SHA3_224 :
931- case MLD_SHA3_256 :
932- case MLD_SHA3_384 :
933- case MLD_SHA3_512 :
934- case MLD_SHAKE_128 :
935959 default :
936960 return -1 ;
937961 }
0 commit comments