static int32 md4_compress(psMd4_t *md, const unsigned char *buf) { int32 err; err = _md4_compress(md, buf); psBurnStack(sizeof(uint32) * 20 + sizeof(int32)); return err; }
static int32 md4_compress(psDigestContext_t *md, unsigned char *buf) { int32 err; err = _md4_compress(md, buf); psBurnStack(sizeof(uint32) * 20 + sizeof(int32)); return err; }
/* Clear the stack deeper than the caller to erase any potential secrets or keys. */ void psBurnStack(uint32 len) { unsigned char buf[32]; memset(buf, 0x0, sizeof(buf)); if (len > (uint32)sizeof(buf)) { psBurnStack(len - sizeof(buf)); } }
int32 psSha512Final(psDigestContext_t * md, unsigned char *out) { int i; psAssert(md != NULL); psAssert(out != NULL); if (md->sha512.curlen >= sizeof(md->sha512.buf)) { return PS_ARG_FAIL; } /* increase the length of the message */ md->sha512.length += md->sha512.curlen * CONST64(8); /* append the '1' bit */ md->sha512.buf[md->sha512.curlen++] = (unsigned char)0x80; /* if the length is currently above 112 bytes we append zeros * then compress. Then we can fall back to padding zeros and length * encoding like normal. */ if (md->sha512.curlen > 112) { while (md->sha512.curlen < 128) { md->sha512.buf[md->sha512.curlen++] = (unsigned char)0; } sha512_compress(md, md->sha512.buf); md->sha512.curlen = 0; } /* pad upto 120 bytes of zeroes * note: that from 112 to 120 is the 64 MSB of the length. We assume that you won't hash * > 2^64 bits of data... :-) */ while (md->sha512.curlen < 120) { md->sha512.buf[md->sha512.curlen++] = (unsigned char)0; } /* store length */ STORE64H(md->sha512.length, md->sha512.buf+120); sha512_compress(md, md->sha512.buf); /* copy output */ for (i = 0; i < 8; i++) { STORE64H(md->sha512.state[i], out+(8*i)); } #ifdef USE_BURN_STACK psBurnStack(sizeof(psDigestContext_t)); #endif return SHA512_HASH_SIZE; }
void psSha224Final(psSha256_t *sha256, unsigned char out[SHA224_HASHLEN]) { unsigned char buf[SHA224_HASHLEN]; #ifdef CRYPTO_ASSERT psAssert(sha256 != NULL); psAssert(out != NULL); #endif psSha256Final(sha256, buf); memcpy(out, buf, SHA224_HASH_SIZE); #ifdef USE_BURN_STACK psBurnStack(sizeof(buf)); #endif }
int32 psSha224Final(psDigestContext_t *md, unsigned char *out) { unsigned char buf[32]; int32 err; psAssert(md != NULL); psAssert(out != NULL); err = psSha256Final(md, buf); memcpy(out, buf, SHA224_HASH_SIZE); #ifdef USE_BURN_STACK psBurnStack(sizeof(buf)); #endif return err; }
void sha512_compress(psDigestContext_t * md, unsigned char *buf) { _sha512_compress(md, buf); psBurnStack(sizeof(uint64) * 90 + sizeof(int)); }
static void sha256_compress(psSha256_t *sha256, const unsigned char *buf) { _sha256_compress(sha256, buf); psBurnStack(sizeof(uint32) * 74); }
void sha256_compress(psDigestContext_t *md, unsigned char *buf) { _sha256_compress(md, buf); psBurnStack(sizeof(uint32) * 74); }
static void sha1_compress(psDigestContext_t *md) { _sha1_compress(md); psBurnStack(sizeof(uint32) * 87); }
static void sha1_compress(hash_state *md) { _sha1_compress(md); psBurnStack(sizeof(unsigned long) * 87); }