os/ossrv/ssl/libcrypto/src/crypto/dsa/dsa_asn1.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/dsa/dsa_asn1.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,147 @@
     1.4 +/* dsa_asn1.c */
     1.5 +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
     1.6 + * project 2000.
     1.7 + */
     1.8 +/* ====================================================================
     1.9 + * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
    1.10 + *
    1.11 + * Redistribution and use in source and binary forms, with or without
    1.12 + * modification, are permitted provided that the following conditions
    1.13 + * are met:
    1.14 + *
    1.15 + * 1. Redistributions of source code must retain the above copyright
    1.16 + *    notice, this list of conditions and the following disclaimer. 
    1.17 + *
    1.18 + * 2. Redistributions in binary form must reproduce the above copyright
    1.19 + *    notice, this list of conditions and the following disclaimer in
    1.20 + *    the documentation and/or other materials provided with the
    1.21 + *    distribution.
    1.22 + *
    1.23 + * 3. All advertising materials mentioning features or use of this
    1.24 + *    software must display the following acknowledgment:
    1.25 + *    "This product includes software developed by the OpenSSL Project
    1.26 + *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
    1.27 + *
    1.28 + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
    1.29 + *    endorse or promote products derived from this software without
    1.30 + *    prior written permission. For written permission, please contact
    1.31 + *    licensing@OpenSSL.org.
    1.32 + *
    1.33 + * 5. Products derived from this software may not be called "OpenSSL"
    1.34 + *    nor may "OpenSSL" appear in their names without prior written
    1.35 + *    permission of the OpenSSL Project.
    1.36 + *
    1.37 + * 6. Redistributions of any form whatsoever must retain the following
    1.38 + *    acknowledgment:
    1.39 + *    "This product includes software developed by the OpenSSL Project
    1.40 + *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
    1.41 + *
    1.42 + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
    1.43 + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.45 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
    1.46 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.47 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    1.48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    1.49 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.50 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.51 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.52 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    1.53 + * OF THE POSSIBILITY OF SUCH DAMAGE.
    1.54 + * ====================================================================
    1.55 + *
    1.56 + * This product includes cryptographic software written by Eric Young
    1.57 + * (eay@cryptsoft.com).  This product includes software written by Tim
    1.58 + * Hudson (tjh@cryptsoft.com).
    1.59 + *
    1.60 + */
    1.61 +
    1.62 +#include <stdio.h>
    1.63 +#include "cryptlib.h"
    1.64 +#include <openssl/dsa.h>
    1.65 +#include <openssl/asn1.h>
    1.66 +#include <openssl/asn1t.h>
    1.67 +
    1.68 +/* Override the default new methods */
    1.69 +static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
    1.70 +{
    1.71 +	if(operation == ASN1_OP_NEW_PRE) {
    1.72 +		DSA_SIG *sig;
    1.73 +		sig = OPENSSL_malloc(sizeof(DSA_SIG));
    1.74 +#ifdef SYMBIAN
    1.75 +  if(sig==NULL)
    1.76 +  {
    1.77 +  	DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
    1.78 +  	return 0;
    1.79 +  }	
    1.80 +#endif		
    1.81 +		sig->r = NULL;
    1.82 +		sig->s = NULL;
    1.83 +		*pval = (ASN1_VALUE *)sig;
    1.84 +		if(sig) return 2;
    1.85 +		DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
    1.86 +		return 0;
    1.87 +	}
    1.88 +	return 1;
    1.89 +}
    1.90 +
    1.91 +ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
    1.92 +	ASN1_SIMPLE(DSA_SIG, r, CBIGNUM),
    1.93 +	ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
    1.94 +} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
    1.95 +
    1.96 +IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)
    1.97 +
    1.98 +/* Override the default free and new methods */
    1.99 +static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
   1.100 +{
   1.101 +	if(operation == ASN1_OP_NEW_PRE) {
   1.102 +		*pval = (ASN1_VALUE *)DSA_new();
   1.103 +		if(*pval) return 2;
   1.104 +		return 0;
   1.105 +	} else if(operation == ASN1_OP_FREE_PRE) {
   1.106 +		DSA_free((DSA *)*pval);
   1.107 +		*pval = NULL;
   1.108 +		return 2;
   1.109 +	}
   1.110 +	return 1;
   1.111 +}
   1.112 +
   1.113 +ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
   1.114 +	ASN1_SIMPLE(DSA, version, LONG),
   1.115 +	ASN1_SIMPLE(DSA, p, BIGNUM),
   1.116 +	ASN1_SIMPLE(DSA, q, BIGNUM),
   1.117 +	ASN1_SIMPLE(DSA, g, BIGNUM),
   1.118 +	ASN1_SIMPLE(DSA, pub_key, BIGNUM),
   1.119 +	ASN1_SIMPLE(DSA, priv_key, BIGNUM)
   1.120 +} ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
   1.121 +
   1.122 +IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPrivateKey, DSAPrivateKey)
   1.123 +
   1.124 +ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
   1.125 +	ASN1_SIMPLE(DSA, p, BIGNUM),
   1.126 +	ASN1_SIMPLE(DSA, q, BIGNUM),
   1.127 +	ASN1_SIMPLE(DSA, g, BIGNUM),
   1.128 +} ASN1_SEQUENCE_END_cb(DSA, DSAparams)
   1.129 +
   1.130 +IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)
   1.131 +
   1.132 +/* DSA public key is a bit trickier... its effectively a CHOICE type
   1.133 + * decided by a field called write_params which can either write out
   1.134 + * just the public key as an INTEGER or the parameters and public key
   1.135 + * in a SEQUENCE
   1.136 + */
   1.137 +
   1.138 +ASN1_SEQUENCE(dsa_pub_internal) = {
   1.139 +	ASN1_SIMPLE(DSA, pub_key, BIGNUM),
   1.140 +	ASN1_SIMPLE(DSA, p, BIGNUM),
   1.141 +	ASN1_SIMPLE(DSA, q, BIGNUM),
   1.142 +	ASN1_SIMPLE(DSA, g, BIGNUM)
   1.143 +} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)
   1.144 +
   1.145 +ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
   1.146 +	ASN1_SIMPLE(DSA, pub_key, BIGNUM),
   1.147 +	ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
   1.148 +} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
   1.149 +
   1.150 +IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)