1160814Ssimon/* crypto/evp/m_ecdsa.c */ 2160814Ssimon/* ==================================================================== 3160814Ssimon * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 4160814Ssimon * 5160814Ssimon * Redistribution and use in source and binary forms, with or without 6160814Ssimon * modification, are permitted provided that the following conditions 7160814Ssimon * are met: 8160814Ssimon * 9160814Ssimon * 1. Redistributions of source code must retain the above copyright 10280297Sjkim * notice, this list of conditions and the following disclaimer. 11160814Ssimon * 12160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 13160814Ssimon * notice, this list of conditions and the following disclaimer in 14160814Ssimon * the documentation and/or other materials provided with the 15160814Ssimon * distribution. 16160814Ssimon * 17160814Ssimon * 3. All advertising materials mentioning features or use of this 18160814Ssimon * software must display the following acknowledgment: 19160814Ssimon * "This product includes software developed by the OpenSSL Project 20160814Ssimon * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21160814Ssimon * 22160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23160814Ssimon * endorse or promote products derived from this software without 24160814Ssimon * prior written permission. For written permission, please contact 25160814Ssimon * openssl-core@openssl.org. 26160814Ssimon * 27160814Ssimon * 5. Products derived from this software may not be called "OpenSSL" 28160814Ssimon * nor may "OpenSSL" appear in their names without prior written 29160814Ssimon * permission of the OpenSSL Project. 30160814Ssimon * 31160814Ssimon * 6. Redistributions of any form whatsoever must retain the following 32160814Ssimon * acknowledgment: 33160814Ssimon * "This product includes software developed by the OpenSSL Project 34160814Ssimon * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35160814Ssimon * 36160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39160814Ssimon * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE. 48160814Ssimon * ==================================================================== 49160814Ssimon * 50160814Ssimon * This product includes cryptographic software written by Eric Young 51160814Ssimon * (eay@cryptsoft.com). This product includes software written by Tim 52160814Ssimon * Hudson (tjh@cryptsoft.com). 53160814Ssimon * 54160814Ssimon */ 55160814Ssimon/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 56160814Ssimon * All rights reserved. 57160814Ssimon * 58160814Ssimon * This package is an SSL implementation written 59160814Ssimon * by Eric Young (eay@cryptsoft.com). 60160814Ssimon * The implementation was written so as to conform with Netscapes SSL. 61280297Sjkim * 62160814Ssimon * This library is free for commercial and non-commercial use as long as 63160814Ssimon * the following conditions are aheared to. The following conditions 64160814Ssimon * apply to all code found in this distribution, be it the RC4, RSA, 65160814Ssimon * lhash, DES, etc., code; not just the SSL code. The SSL documentation 66160814Ssimon * included with this distribution is covered by the same copyright terms 67160814Ssimon * except that the holder is Tim Hudson (tjh@cryptsoft.com). 68280297Sjkim * 69160814Ssimon * Copyright remains Eric Young's, and as such any Copyright notices in 70160814Ssimon * the code are not to be removed. 71160814Ssimon * If this package is used in a product, Eric Young should be given attribution 72160814Ssimon * as the author of the parts of the library used. 73160814Ssimon * This can be in the form of a textual message at program startup or 74160814Ssimon * in documentation (online or textual) provided with the package. 75280297Sjkim * 76160814Ssimon * Redistribution and use in source and binary forms, with or without 77160814Ssimon * modification, are permitted provided that the following conditions 78160814Ssimon * are met: 79160814Ssimon * 1. Redistributions of source code must retain the copyright 80160814Ssimon * notice, this list of conditions and the following disclaimer. 81160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 82160814Ssimon * notice, this list of conditions and the following disclaimer in the 83160814Ssimon * documentation and/or other materials provided with the distribution. 84160814Ssimon * 3. All advertising materials mentioning features or use of this software 85160814Ssimon * must display the following acknowledgement: 86160814Ssimon * "This product includes cryptographic software written by 87160814Ssimon * Eric Young (eay@cryptsoft.com)" 88160814Ssimon * The word 'cryptographic' can be left out if the rouines from the library 89160814Ssimon * being used are not cryptographic related :-). 90280297Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from 91160814Ssimon * the apps directory (application code) you must include an acknowledgement: 92160814Ssimon * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 93280297Sjkim * 94160814Ssimon * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 95160814Ssimon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 96160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 97160814Ssimon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 98160814Ssimon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 99160814Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 100160814Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 101160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 102160814Ssimon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 103160814Ssimon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 104160814Ssimon * SUCH DAMAGE. 105280297Sjkim * 106160814Ssimon * The licence and distribution terms for any publically available version or 107160814Ssimon * derivative of this code cannot be changed. i.e. this code cannot simply be 108160814Ssimon * copied and put under another distribution licence 109160814Ssimon * [including the GNU Public Licence.] 110160814Ssimon */ 111160814Ssimon 112160814Ssimon#include <stdio.h> 113160814Ssimon#include "cryptlib.h" 114160814Ssimon#include <openssl/evp.h> 115160814Ssimon#include <openssl/objects.h> 116160814Ssimon#include <openssl/x509.h> 117160814Ssimon 118160814Ssimon#ifndef OPENSSL_NO_SHA 119238405Sjkim 120160814Ssimonstatic int init(EVP_MD_CTX *ctx) 121280297Sjkim{ 122280297Sjkim return SHA1_Init(ctx->md_data); 123280297Sjkim} 124160814Ssimon 125280297Sjkimstatic int update(EVP_MD_CTX *ctx, const void *data, size_t count) 126280297Sjkim{ 127280297Sjkim return SHA1_Update(ctx->md_data, data, count); 128280297Sjkim} 129160814Ssimon 130280297Sjkimstatic int final(EVP_MD_CTX *ctx, unsigned char *md) 131280297Sjkim{ 132280297Sjkim return SHA1_Final(md, ctx->md_data); 133280297Sjkim} 134160814Ssimon 135280297Sjkimstatic const EVP_MD ecdsa_md = { 136280297Sjkim NID_ecdsa_with_SHA1, 137280297Sjkim NID_ecdsa_with_SHA1, 138280297Sjkim SHA_DIGEST_LENGTH, 139280297Sjkim EVP_MD_FLAG_PKEY_DIGEST, 140280297Sjkim init, 141280297Sjkim update, 142280297Sjkim final, 143280297Sjkim NULL, 144280297Sjkim NULL, 145280297Sjkim EVP_PKEY_ECDSA_method, 146280297Sjkim SHA_CBLOCK, 147280297Sjkim sizeof(EVP_MD *) + sizeof(SHA_CTX), 148280297Sjkim}; 149160814Ssimon 150160814Ssimonconst EVP_MD *EVP_ecdsa(void) 151280297Sjkim{ 152280297Sjkim return (&ecdsa_md); 153280297Sjkim} 154160814Ssimon#endif 155