static INLINE int Sha512Final(Sha512* sha512) { byte* local = (byte*)sha512->buffer; int ret; SAVE_XMM_YMM ; /* for Intel AVX */ AddLength(sha512, sha512->buffLen); /* before adding pads */ local[sha512->buffLen++] = 0x80; /* add 1 */ /* pad with zeros */ if (sha512->buffLen > SHA512_PAD_SIZE) { XMEMSET(&local[sha512->buffLen], 0, SHA512_BLOCK_SIZE -sha512->buffLen); sha512->buffLen += SHA512_BLOCK_SIZE - sha512->buffLen; #if defined(LITTLE_ENDIAN_ORDER) #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2) if(!IS_INTEL_AVX1 && !IS_INTEL_AVX2) #endif ByteReverseWords64(sha512->buffer,sha512->buffer,SHA512_BLOCK_SIZE); #endif ret = Transform(sha512); if (ret != 0) return ret; sha512->buffLen = 0; } XMEMSET(&local[sha512->buffLen], 0, SHA512_PAD_SIZE - sha512->buffLen); /* put lengths in bits */ sha512->hiLen = (sha512->loLen >> (8*sizeof(sha512->loLen) - 3)) + (sha512->hiLen << 3); sha512->loLen = sha512->loLen << 3; /* store lengths */ #if defined(LITTLE_ENDIAN_ORDER) #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2) if(!IS_INTEL_AVX1 && !IS_INTEL_AVX2) #endif ByteReverseWords64(sha512->buffer, sha512->buffer, SHA512_PAD_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ sha512->buffer[SHA512_BLOCK_SIZE / sizeof(word64) - 2] = sha512->hiLen; sha512->buffer[SHA512_BLOCK_SIZE / sizeof(word64) - 1] = sha512->loLen; #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2) if(IS_INTEL_AVX1 || IS_INTEL_AVX2) ByteReverseWords64(&(sha512->buffer[SHA512_BLOCK_SIZE / sizeof(word64) - 2]), &(sha512->buffer[SHA512_BLOCK_SIZE / sizeof(word64) - 2]), SHA512_BLOCK_SIZE - SHA512_PAD_SIZE); #endif ret = Transform(sha512); if (ret != 0) return ret; #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha512->digest, sha512->digest, SHA512_DIGEST_SIZE); #endif return 0; }
int wc_Sha384Final(Sha384* sha384, byte* hash) { byte* local = (byte*)sha384->buffer; int ret; AddLength384(sha384, sha384->buffLen); /* before adding pads */ local[sha384->buffLen++] = 0x80; /* add 1 */ /* pad with zeros */ if (sha384->buffLen > SHA384_PAD_SIZE) { XMEMSET(&local[sha384->buffLen], 0, SHA384_BLOCK_SIZE -sha384->buffLen); sha384->buffLen += SHA384_BLOCK_SIZE - sha384->buffLen; #if defined(LITTLE_ENDIAN_ORDER) ByteReverseWords64(sha384->buffer, sha384->buffer, SHA384_BLOCK_SIZE); #endif ret = _Transform384(sha384); if (ret != 0) return ret; sha384->buffLen = 0; } XMEMSET(&local[sha384->buffLen], 0, SHA384_PAD_SIZE - sha384->buffLen); /* put lengths in bits */ sha384->hiLen = (sha384->loLen >> (8*sizeof(sha384->loLen) - 3)) + (sha384->hiLen << 3); sha384->loLen = sha384->loLen << 3; /* store lengths */ #if defined(LITTLE_ENDIAN_ORDER) ByteReverseWords64(sha384->buffer, sha384->buffer, SHA384_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ sha384->buffer[SHA384_BLOCK_SIZE / sizeof(word64) - 2] = sha384->hiLen; sha384->buffer[SHA384_BLOCK_SIZE / sizeof(word64) - 1] = sha384->loLen; ret = _Transform384(sha384); if (ret != 0) return ret; #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha384->digest, sha384->digest, SHA384_DIGEST_SIZE); #endif XMEMCPY(hash, sha384->digest, SHA384_DIGEST_SIZE); return wc_InitSha384(sha384); /* reset state */ }
int Sha384Update(Sha384* sha384, const byte* data, word32 len) { /* do block size increments */ byte* local = (byte*)sha384->buffer; while (len) { word32 add = min(len, SHA384_BLOCK_SIZE - sha384->buffLen); XMEMCPY(&local[sha384->buffLen], data, add); sha384->buffLen += add; data += add; len -= add; if (sha384->buffLen == SHA384_BLOCK_SIZE) { int ret; #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha384->buffer, sha384->buffer, SHA384_BLOCK_SIZE); #endif ret = Transform384(sha384); if (ret != 0) return ret; AddLength384(sha384, SHA384_BLOCK_SIZE); sha384->buffLen = 0; } } return 0; }
int wc_Sha512Update(Sha512* sha512, const byte* data, word32 len) { /* do block size increments */ byte* local = (byte*)sha512->buffer; while (len) { word32 add = min(len, SHA512_BLOCK_SIZE - sha512->buffLen); XMEMCPY(&local[sha512->buffLen], data, add); sha512->buffLen += add; data += add; len -= add; if (sha512->buffLen == SHA512_BLOCK_SIZE) { int ret; #if defined(LITTLE_ENDIAN_ORDER) ByteReverseWords64(sha512->buffer, sha512->buffer, SHA512_BLOCK_SIZE); #endif ret = _Transform(sha512); if (ret != 0) return ret; AddLength(sha512, SHA512_BLOCK_SIZE); sha512->buffLen = 0; } } return 0; }
static INLINE int Sha512Update(Sha512* sha512, const byte* data, word32 len) { /* do block size increments */ byte* local = (byte*)sha512->buffer; SAVE_XMM_YMM ; /* for Intel AVX */ while (len) { word32 add = min(len, SHA512_BLOCK_SIZE - sha512->buffLen); XMEMCPY(&local[sha512->buffLen], data, add); sha512->buffLen += add; data += add; len -= add; if (sha512->buffLen == SHA512_BLOCK_SIZE) { int ret; #if defined(LITTLE_ENDIAN_ORDER) #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2) if(!IS_INTEL_AVX1 && !IS_INTEL_AVX2) #endif ByteReverseWords64(sha512->buffer, sha512->buffer, SHA512_BLOCK_SIZE); #endif ret = Transform(sha512); if (ret != 0) return ret; AddLength(sha512, SHA512_BLOCK_SIZE); sha512->buffLen = 0; } } return 0; }
void Sha512Final(Sha512* sha512, byte* hash) { byte* local = (byte*)sha512->buffer; AddLength(sha512, sha512->buffLen); /* before adding pads */ local[sha512->buffLen++] = 0x80; /* add 1 */ /* pad with zeros */ if (sha512->buffLen > SHA512_PAD_SIZE) { XMEMSET(&local[sha512->buffLen], 0, SHA512_BLOCK_SIZE - sha512->buffLen); sha512->buffLen += SHA512_BLOCK_SIZE - sha512->buffLen; #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha512->buffer,sha512->buffer,SHA512_BLOCK_SIZE); #endif Transform(sha512); sha512->buffLen = 0; } XMEMSET(&local[sha512->buffLen], 0, SHA512_PAD_SIZE - sha512->buffLen); /* put lengths in bits */ sha512->loLen = sha512->loLen << 3; sha512->hiLen = (sha512->loLen >> (8*sizeof(sha512->loLen) - 3)) + (sha512->hiLen << 3); /* store lengths */ #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha512->buffer, sha512->buffer, SHA512_PAD_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ sha512->buffer[SHA512_BLOCK_SIZE / sizeof(word64) - 2] = sha512->hiLen; sha512->buffer[SHA512_BLOCK_SIZE / sizeof(word64) - 1] = sha512->loLen; Transform(sha512); #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha512->digest, sha512->digest, SHA512_DIGEST_SIZE); #endif XMEMCPY(hash, sha512->digest, SHA512_DIGEST_SIZE); InitSha512(sha512); /* reset state */ }
void Sha512Update(Sha512* sha512, const byte* data, word32 len) { /* do block size increments */ byte* local = (byte*)sha512->buffer; while (len) { word32 add = min(len, SHA512_BLOCK_SIZE - sha512->buffLen); memcpy(&local[sha512->buffLen], data, add); sha512->buffLen += add; data += add; len -= add; if (sha512->buffLen == SHA512_BLOCK_SIZE) { #ifdef LITTLE_ENDIAN_ORDER ByteReverseWords64(sha512->buffer, sha512->buffer, SHA512_BLOCK_SIZE); #endif Transform(sha512); AddLength(sha512, SHA512_BLOCK_SIZE); sha512->buffLen = 0; } } }