1 /* 2 * Special version of sha256.c that uses the libc SHA256 implementation 3 * of libc. 4 */ 5 6 /* crypto/sha/sha256.c */ 7 /* ==================================================================== 8 * Copyright (c) 2004 The OpenSSL Project. All rights reserved 9 * according to the OpenSSL license [found in ../../LICENSE]. 10 * ==================================================================== 11 */ 12 #include <openssl/opensslconf.h> 13 14 #include <stdlib.h> 15 #include <string.h> 16 17 #include <openssl/crypto.h> 18 #include <openssl/sha.h> 19 #include <openssl/opensslv.h> 20 21 #include "cryptlib.h" 22 23 const char SHA256_version[]="SHA-256" OPENSSL_VERSION_PTEXT; 24 25 unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md) 26 { 27 SHA256_CTX c; 28 static unsigned char m[SHA224_DIGEST_LENGTH]; 29 30 if (md == NULL) md=m; 31 SHA224_Init(&c); 32 SHA224_Update(&c,d,n); 33 SHA224_Final(md,&c); 34 OPENSSL_cleanse(&c,sizeof(c)); 35 return(md); 36 } 37 38 unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md) 39 { 40 SHA256_CTX c; 41 static unsigned char m[SHA256_DIGEST_LENGTH]; 42 43 if (md == NULL) md=m; 44 SHA256_Init(&c); 45 SHA256_Update(&c,d,n); 46 SHA256_Final(md,&c); 47 OPENSSL_cleanse(&c,sizeof(c)); 48 return(md); 49 } 50