/* hash.c version 20151120 Andreas Hülsing Public domain. */ #include "prg.h" #include #include "stdio.h" #include #include #include #define SET_KEY_BIT(a,b) (a[15] = (a[15] & 253) | (b << 1)) #define SET_BLOCK_BIT(a,b) (a[15] = (a[15] & 254) | b) #define WOTS_SELECT_KEY(a) (a[15] = (a[15] & 254) | 1) #define WOTS_SELECT_BLOCK(a) (a[15] = (a[15] & 254) | 0) /** * Implements PRF_m */ int prf_m(unsigned char *out, const unsigned char *in, size_t inlen, const unsigned char *key, int keylen) { unsigned int length; if (keylen == 32){ HMAC(EVP_sha256(), key, keylen, in, inlen, out, &length); if(length != 32) { fprintf(stderr, "HMAC outputs %d bytes... That should not happen...",length); } return 0; } else { if(keylen == 64) { HMAC(EVP_sha512(), key, keylen, in, inlen, out, &length); if(length != 64) { fprintf(stderr, "HMAC outputs %d bytes... That should not happen...",length); } return 0; } } return 1; } /* * Implemts H_m */ int hash_m(unsigned char *out,const unsigned char *in,unsigned long long inlen,const unsigned char *key, const int keylen, const int m) { if(keylen != m){ fprintf(stderr, "H_m takes m-bit keys, we got m=%d but a keylength of %d.\n",m,keylen); return 1; } unsigned long long i; unsigned char buf[inlen +keylen+m]; for(i=0;i