1139749Simp/* crypto/evp/m_sha1.c */ 272017Scg/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 372017Scg * All rights reserved. 472017Scg * 572017Scg * This package is an SSL implementation written 672017Scg * by Eric Young (eay@cryptsoft.com). 772017Scg * The implementation was written so as to conform with Netscapes SSL. 872017Scg * 972017Scg * This library is free for commercial and non-commercial use as long as 1072017Scg * the following conditions are aheared to. The following conditions 1172017Scg * apply to all code found in this distribution, be it the RC4, RSA, 1272017Scg * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1372017Scg * included with this distribution is covered by the same copyright terms 1472017Scg * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1572017Scg * 1672017Scg * Copyright remains Eric Young's, and as such any Copyright notices in 1772017Scg * the code are not to be removed. 1872017Scg * If this package is used in a product, Eric Young should be given attribution 1972017Scg * as the author of the parts of the library used. 2072017Scg * This can be in the form of a textual message at program startup or 2172017Scg * in documentation (online or textual) provided with the package. 2272017Scg * 2372017Scg * Redistribution and use in source and binary forms, with or without 2472017Scg * modification, are permitted provided that the following conditions 25192919Sjoel * are met: 26192919Sjoel * 1. Redistributions of source code must retain the copyright 27192919Sjoel * notice, this list of conditions and the following disclaimer. 2872017Scg * 2. Redistributions in binary form must reproduce the above copyright 2972017Scg * notice, this list of conditions and the following disclaimer in the 3072455Scg * documentation and/or other materials provided with the distribution. 3172455Scg * 3. All advertising materials mentioning features or use of this software 3272455Scg * must display the following acknowledgement: 3372017Scg * "This product includes cryptographic software written by 34193640Sariff * Eric Young (eay@cryptsoft.com)" 35193640Sariff * The word 'cryptographic' can be left out if the rouines from the library 36193640Sariff * being used are not cryptographic related :-). 37193640Sariff * 4. If you include any Windows specific code (or a derivative thereof) from 3872017Scg * the apps directory (application code) you must include an acknowledgement: 3972017Scg * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4072017Scg * 41119287Simp * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42119287Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4372017Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4472017Scg * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4572017Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4682180Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4782180Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4884771Sorion * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4972017Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5072017Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5172017Scg * SUCH DAMAGE. 5272017Scg * 5372017Scg * The licence and distribution terms for any publically available version or 5472017Scg * derivative of this code cannot be changed. i.e. this code cannot simply be 5572017Scg * copied and put under another distribution licence 5672017Scg * [including the GNU Public Licence.] 5772017Scg */ 5872017Scg 5972017Scg#include <stdio.h> 6072017Scg#include "cryptlib.h" 6172017Scg 6272017Scg#ifndef OPENSSL_FIPS 6372017Scg 6472017Scg#ifndef OPENSSL_NO_SHA 6572017Scg 6672017Scg#include <openssl/evp.h> 6772017Scg#include <openssl/objects.h> 6872017Scg#include <openssl/sha.h> 6972017Scg#ifndef OPENSSL_NO_RSA 7072017Scg#include <openssl/rsa.h> 7172017Scg#endif 7272017Scg 7372017Scg 7474763Scgstatic int init(EVP_MD_CTX *ctx) 7574763Scg { return SHA1_Init(ctx->md_data); } 7672017Scg 7772455Scgstatic int update(EVP_MD_CTX *ctx,const void *data,size_t count) 7872455Scg { return SHA1_Update(ctx->md_data,data,count); } 7972455Scg 8072017Scgstatic int final(EVP_MD_CTX *ctx,unsigned char *md) 8172017Scg { return SHA1_Final(md,ctx->md_data); } 8272017Scg 8372017Scgstatic const EVP_MD sha1_md= 8472017Scg { 8572017Scg NID_sha1, 8672017Scg NID_sha1WithRSAEncryption, 8772017Scg SHA_DIGEST_LENGTH, 8872017Scg EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT, 8972017Scg init, 9072017Scg update, 9172017Scg final, 9272017Scg NULL, 9372017Scg NULL, 9472017Scg EVP_PKEY_RSA_method, 9572017Scg SHA_CBLOCK, 9684771Sorion sizeof(EVP_MD *)+sizeof(SHA_CTX), 9772017Scg }; 9872017Scg 9972017Scgconst EVP_MD *EVP_sha1(void) 10072017Scg { 10172017Scg return(&sha1_md); 10272017Scg } 10372017Scg#endif 10472017Scg 10572017Scg#ifndef OPENSSL_NO_SHA256 10672017Scgstatic int init224(EVP_MD_CTX *ctx) 10772017Scg { return SHA224_Init(ctx->md_data); } 10872455Scgstatic int init256(EVP_MD_CTX *ctx) 10972017Scg { return SHA256_Init(ctx->md_data); } 11072017Scgstatic int update224(EVP_MD_CTX *ctx,const void *data,size_t count) 11172017Scg { return SHA224_Update(ctx->md_data,data,count); } 11272017Scgstatic int update256(EVP_MD_CTX *ctx,const void *data,size_t count) 11372017Scg { return SHA256_Update(ctx->md_data,data,count); } 11472017Scgstatic int final224(EVP_MD_CTX *ctx,unsigned char *md) 11572017Scg { return SHA224_Final(md,ctx->md_data); } 11672017Scgstatic int final256(EVP_MD_CTX *ctx,unsigned char *md) 11772017Scg { return SHA256_Final(md,ctx->md_data); } 11872017Scg 11972017Scgstatic const EVP_MD sha224_md= 12072017Scg { 12172017Scg NID_sha224, 12272017Scg NID_sha224WithRSAEncryption, 12372017Scg SHA224_DIGEST_LENGTH, 12472017Scg EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT, 12572017Scg init224, 126193640Sariff update224, 127193640Sariff final224, 128193640Sariff NULL, 129193640Sariff NULL, 130193640Sariff EVP_PKEY_RSA_method, 131193640Sariff SHA256_CBLOCK, 132193640Sariff sizeof(EVP_MD *)+sizeof(SHA256_CTX), 133193640Sariff }; 134193640Sariff 135193640Sariffconst EVP_MD *EVP_sha224(void) 136193640Sariff { return(&sha224_md); } 137193640Sariff 13872017Scgstatic const EVP_MD sha256_md= 13972017Scg { 14072017Scg NID_sha256, 14174763Scg NID_sha256WithRSAEncryption, 14272017Scg SHA256_DIGEST_LENGTH, 14372017Scg EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT, 14472017Scg init256, 14572017Scg update256, 14672017Scg final256, 14772017Scg NULL, 14872017Scg NULL, 14972017Scg EVP_PKEY_RSA_method, 15072017Scg SHA256_CBLOCK, 15172017Scg sizeof(EVP_MD *)+sizeof(SHA256_CTX), 15272017Scg }; 15372017Scg 15472017Scgconst EVP_MD *EVP_sha256(void) 15572017Scg { return(&sha256_md); } 15672017Scg#endif /* ifndef OPENSSL_NO_SHA256 */ 15772017Scg 15872017Scg#ifndef OPENSSL_NO_SHA512 15972017Scgstatic int init384(EVP_MD_CTX *ctx) 16072017Scg { return SHA384_Init(ctx->md_data); } 16172017Scgstatic int init512(EVP_MD_CTX *ctx) 16272017Scg { return SHA512_Init(ctx->md_data); } 16372017Scg/* See comment in SHA224/256 section */ 16472017Scgstatic int update384(EVP_MD_CTX *ctx,const void *data,size_t count) 16572017Scg { return SHA384_Update(ctx->md_data,data,count); } 16672017Scgstatic int update512(EVP_MD_CTX *ctx,const void *data,size_t count) 16772017Scg { return SHA512_Update(ctx->md_data,data,count); } 16872017Scgstatic int final384(EVP_MD_CTX *ctx,unsigned char *md) 16972017Scg { return SHA384_Final(md,ctx->md_data); } 17072017Scgstatic int final512(EVP_MD_CTX *ctx,unsigned char *md) 17172017Scg { return SHA512_Final(md,ctx->md_data); } 17272017Scg 17372017Scgstatic const EVP_MD sha384_md= 17472017Scg { 17572017Scg NID_sha384, 17672017Scg NID_sha384WithRSAEncryption, 17772017Scg SHA384_DIGEST_LENGTH, 17872017Scg EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT, 17972017Scg init384, 180193640Sariff update384, 18172017Scg final384, 18272017Scg NULL, 18372017Scg NULL, 18472017Scg EVP_PKEY_RSA_method, 18572017Scg SHA512_CBLOCK, 18672017Scg sizeof(EVP_MD *)+sizeof(SHA512_CTX), 18772017Scg }; 18872017Scg 18972017Scgconst EVP_MD *EVP_sha384(void) 19072017Scg { return(&sha384_md); } 19172017Scg 19272017Scgstatic const EVP_MD sha512_md= 19372017Scg { 194193640Sariff NID_sha512, 19572017Scg NID_sha512WithRSAEncryption, 19672017Scg SHA512_DIGEST_LENGTH, 19772017Scg EVP_MD_FLAG_PKEY_METHOD_SIGNATURE|EVP_MD_FLAG_DIGALGID_ABSENT, 19872017Scg init512, 19972017Scg update512, 20072017Scg final512, 20172017Scg NULL, 20272017Scg NULL, 20372017Scg EVP_PKEY_RSA_method, 20472017Scg SHA512_CBLOCK, 20572017Scg sizeof(EVP_MD *)+sizeof(SHA512_CTX), 20672017Scg }; 20772017Scg 20872017Scgconst EVP_MD *EVP_sha512(void) 20972455Scg { return(&sha512_md); } 21072017Scg#endif /* ifndef OPENSSL_NO_SHA512 */ 21172017Scg 21272017Scg#endif 21372017Scg