Changeset 94082 in vbox for trunk/src/libs/openssl-3.0.1/crypto/dsa/dsa_asn1.c
- Timestamp:
- Mar 3, 2022 7:17:34 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 150325
- Location:
- trunk/src/libs/openssl-3.0.1
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/openssl-3.0.1
- Property svn:mergeinfo
-
old new 12 12 /vendor/openssl/1.1.1c:131722-131725 13 13 /vendor/openssl/1.1.1k:145841-145843 14 /vendor/openssl/3.0.1:150323-150324 15 /vendor/openssl/current:147554-150322
-
- Property svn:mergeinfo
-
trunk/src/libs/openssl-3.0.1/crypto/dsa/dsa_asn1.c
r91772 r94082 1 1 /* 2 * Copyright 1999-20 16The OpenSSL Project Authors. All Rights Reserved.2 * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. 3 3 * 4 * Licensed under the OpenSSL license(the "License"). You may not use4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 5 * this file except in compliance with the License. You can obtain a copy 6 6 * in the file LICENSE in the source distribution or at 7 7 * https://www.openssl.org/source/license.html 8 8 */ 9 10 /* 11 * DSA low level APIs are deprecated for public use, but still ok for 12 * internal use. 13 */ 14 #include "internal/deprecated.h" 9 15 10 16 #include <stdio.h> … … 14 20 #include <openssl/asn1t.h> 15 21 #include <openssl/rand.h> 16 17 ASN1_SEQUENCE(DSA_SIG) = { 18 ASN1_SIMPLE(DSA_SIG, r, CBIGNUM), 19 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) 20 } static_ASN1_SEQUENCE_END(DSA_SIG) 21 22 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG, DSA_SIG, DSA_SIG) 23 24 DSA_SIG *DSA_SIG_new(void) 25 { 26 DSA_SIG *sig = OPENSSL_zalloc(sizeof(*sig)); 27 if (sig == NULL) 28 DSAerr(DSA_F_DSA_SIG_NEW, ERR_R_MALLOC_FAILURE); 29 return sig; 30 } 31 32 void DSA_SIG_free(DSA_SIG *sig) 33 { 34 if (sig == NULL) 35 return; 36 BN_clear_free(sig->r); 37 BN_clear_free(sig->s); 38 OPENSSL_free(sig); 39 } 40 41 void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) 42 { 43 if (pr != NULL) 44 *pr = sig->r; 45 if (ps != NULL) 46 *ps = sig->s; 47 } 48 49 int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s) 50 { 51 if (r == NULL || s == NULL) 52 return 0; 53 BN_clear_free(sig->r); 54 BN_clear_free(sig->s); 55 sig->r = r; 56 sig->s = s; 57 return 1; 58 } 22 #include "crypto/asn1_dsa.h" 59 23 60 24 /* Override the default free and new methods */ … … 77 41 ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = { 78 42 ASN1_EMBED(DSA, version, INT32), 79 ASN1_SIMPLE(DSA, p , BIGNUM),80 ASN1_SIMPLE(DSA, q, BIGNUM),81 ASN1_SIMPLE(DSA, g, BIGNUM),43 ASN1_SIMPLE(DSA, params.p, BIGNUM), 44 ASN1_SIMPLE(DSA, params.q, BIGNUM), 45 ASN1_SIMPLE(DSA, params.g, BIGNUM), 82 46 ASN1_SIMPLE(DSA, pub_key, BIGNUM), 83 47 ASN1_SIMPLE(DSA, priv_key, CBIGNUM) 84 48 } static_ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey) 85 49 86 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_ const_fname(DSA, DSAPrivateKey, DSAPrivateKey)50 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPrivateKey, DSAPrivateKey) 87 51 88 52 ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = { 89 ASN1_SIMPLE(DSA, p , BIGNUM),90 ASN1_SIMPLE(DSA, q, BIGNUM),91 ASN1_SIMPLE(DSA, g, BIGNUM),53 ASN1_SIMPLE(DSA, params.p, BIGNUM), 54 ASN1_SIMPLE(DSA, params.q, BIGNUM), 55 ASN1_SIMPLE(DSA, params.g, BIGNUM), 92 56 } static_ASN1_SEQUENCE_END_cb(DSA, DSAparams) 93 57 94 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_ const_fname(DSA, DSAparams, DSAparams)58 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAparams, DSAparams) 95 59 96 60 ASN1_SEQUENCE_cb(DSAPublicKey, dsa_cb) = { 97 61 ASN1_SIMPLE(DSA, pub_key, BIGNUM), 98 ASN1_SIMPLE(DSA, p , BIGNUM),99 ASN1_SIMPLE(DSA, q, BIGNUM),100 ASN1_SIMPLE(DSA, g, BIGNUM)62 ASN1_SIMPLE(DSA, params.p, BIGNUM), 63 ASN1_SIMPLE(DSA, params.q, BIGNUM), 64 ASN1_SIMPLE(DSA, params.g, BIGNUM) 101 65 } static_ASN1_SEQUENCE_END_cb(DSA, DSAPublicKey) 102 66 103 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_ const_fname(DSA, DSAPublicKey, DSAPublicKey)67 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPublicKey, DSAPublicKey) 104 68 105 DSA *DSAparams_dup( DSA *dsa)69 DSA *DSAparams_dup(const DSA *dsa) 106 70 { 107 71 return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); 108 72 } 109 110 int DSA_sign(int type, const unsigned char *dgst, int dlen,111 unsigned char *sig, unsigned int *siglen, DSA *dsa)112 {113 DSA_SIG *s;114 115 s = DSA_do_sign(dgst, dlen, dsa);116 if (s == NULL) {117 *siglen = 0;118 return 0;119 }120 *siglen = i2d_DSA_SIG(s, &sig);121 DSA_SIG_free(s);122 return 1;123 }124 125 /* data has already been hashed (probably with SHA or SHA-1). */126 /*-127 * returns128 * 1: correct signature129 * 0: incorrect signature130 * -1: error131 */132 int DSA_verify(int type, const unsigned char *dgst, int dgst_len,133 const unsigned char *sigbuf, int siglen, DSA *dsa)134 {135 DSA_SIG *s;136 const unsigned char *p = sigbuf;137 unsigned char *der = NULL;138 int derlen = -1;139 int ret = -1;140 141 s = DSA_SIG_new();142 if (s == NULL)143 return ret;144 if (d2i_DSA_SIG(&s, &p, siglen) == NULL)145 goto err;146 /* Ensure signature uses DER and doesn't have trailing garbage */147 derlen = i2d_DSA_SIG(s, &der);148 if (derlen != siglen || memcmp(sigbuf, der, derlen))149 goto err;150 ret = DSA_do_verify(dgst, dgst_len, s, dsa);151 err:152 OPENSSL_clear_free(der, derlen);153 DSA_SIG_free(s);154 return ret;155 }
Note:
See TracChangeset
for help on using the changeset viewer.