m_dss.c revision 221304ee937bc0910948a8be1320cb8cc4eb6d36
143811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany/* crypto/evp/m_dss.c */
243811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
343811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * All rights reserved.
443811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany *
543811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * This package is an SSL implementation written
643811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * by Eric Young (eay@cryptsoft.com).
743811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * The implementation was written so as to conform with Netscapes SSL.
843811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany *
943811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * This library is free for commercial and non-commercial use as long as
1043811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * the following conditions are aheared to.  The following conditions
1143811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * apply to all code found in this distribution, be it the RC4, RSA,
1243811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1343811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * included with this distribution is covered by the same copyright terms
1443811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1543811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany *
1643811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * Copyright remains Eric Young's, and as such any Copyright notices in
1743811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * the code are not to be removed.
1843811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * If this package is used in a product, Eric Young should be given attribution
1943811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * as the author of the parts of the library used.
2043811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * This can be in the form of a textual message at program startup or
2143811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * in documentation (online or textual) provided with the package.
22b48224c8d19cac76f2af1eba158b9ae26ed1608aDmitry Vyukov *
2343811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * Redistribution and use in source and binary forms, with or without
2443811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * modification, are permitted provided that the following conditions
2543811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany * are met:
269150f397ba4c5478275d72665ea3e53a84c7076aKostya Serebryany * 1. Redistributions of source code must retain the copyright
279150f397ba4c5478275d72665ea3e53a84c7076aKostya Serebryany *    notice, this list of conditions and the following disclaimer.
289150f397ba4c5478275d72665ea3e53a84c7076aKostya Serebryany * 2. Redistributions in binary form must reproduce the above copyright
29038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany *    notice, this list of conditions and the following disclaimer in the
30038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany *    documentation and/or other materials provided with the distribution.
313661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * 3. All advertising materials mentioning features or use of this software
32f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany *    must display the following acknowledgement:
33f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany *    "This product includes cryptographic software written by
34038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany *     Eric Young (eay@cryptsoft.com)"
35f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany *    The word 'cryptographic' can be left out if the rouines from the library
36038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany *    being used are not cryptographic related :-).
37038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * 4. If you include any Windows specific code (or a derivative thereof) from
38038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany *    the apps directory (application code) you must include an acknowledgement:
39038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany *
41038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
483661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
493661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
503661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
513661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * SUCH DAMAGE.
523661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany *
533661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * The licence and distribution terms for any publically available version or
543661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * derivative of this code cannot be changed.  i.e. this code cannot simply be
553661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany * copied and put under another distribution licence
56038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany * [including the GNU Public Licence.]
573661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany */
583661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany
593661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#include <stdio.h>
603661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#include "cryptlib.h"
613661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#include <openssl/evp.h>
623661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#include <openssl/objects.h>
633661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#include <openssl/x509.h>
643661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#ifndef OPENSSL_NO_DSA
65038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany#include <openssl/dsa.h>
663661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany#endif
67f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany
68f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany#ifndef OPENSSL_NO_SHA
69f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany
70038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryanystatic int init(EVP_MD_CTX *ctx)
71f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	{ return SHA1_Init(ctx->md_data); }
72f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany
73f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryanystatic int update(EVP_MD_CTX *ctx,const void *data,size_t count)
74f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	{ return SHA1_Update(ctx->md_data,data,count); }
75038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany
76f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryanystatic int final(EVP_MD_CTX *ctx,unsigned char *md)
77f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	{ return SHA1_Final(md,ctx->md_data); }
78f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany
79f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryanystatic const EVP_MD dsa_md=
80f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	{
81f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	NID_dsaWithSHA,
82f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	NID_dsaWithSHA,
83f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	SHA_DIGEST_LENGTH,
84f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	EVP_MD_FLAG_PKEY_DIGEST,
85f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	init,
86f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	update,
87f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	final,
88f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	NULL,
8943811a14504f1ff473b40c194a3e9054e2ea46a4Kostya Serebryany	NULL,
907811b4afded19781f940a733d6c64201e5f4b987Kostya Serebryany	EVP_PKEY_DSA_method,
91038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany	SHA_CBLOCK,
923661bae401ea7fb8d61f20466f194ef90d7bdaa2Kostya Serebryany	sizeof(EVP_MD *)+sizeof(SHA_CTX),
93038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany	};
94038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany
95038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryanyconst EVP_MD *EVP_dss(void)
96038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany	{
97f2c417c3b7d7a11f1f6f20edca08af2cb1fad142Kostya Serebryany	return(&dsa_md);
98038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany	}
99038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany#endif
100038820fbab7e77c546b2c37bf674824980320f18Kostya Serebryany