Latest update.

This commit is contained in:
2020-03-03 19:16:19 +09:00
parent f85de4da03
commit b412d79e8b
310 changed files with 32765 additions and 19720 deletions
+22 -17
View File
@@ -15,31 +15,37 @@
#define ASN1_SEQUENCE 0x30
#define ASN1_OID 0x06
/* dsaWithSHA OIDs are of the form: (1 3 14 3 2 |n|) */
#define ENCODE_ALGORITHMIDENTIFIER_SHA(name, n) \
/*
* id-dsa-with-sha1 OBJECT IDENTIFIER ::= {
* iso(1) member-body(2) us(840) x9-57(10040) x9cm(4) 3
* }
*/
#define ENCODE_ALGORITHMIDENTIFIER_RFC3279(name, n) \
static const unsigned char algorithmidentifier_##name##_der[] = { \
ASN1_SEQUENCE, 0x07, \
ASN1_OID, 0x05, 1 * 40 + 3, 14, 3, 2, n \
ASN1_SEQUENCE, 0x09, \
ASN1_OID, 0x07, 1 * 40 + 2, 134, 72, 206, 56, 4, n \
}
ENCODE_ALGORITHMIDENTIFIER_SHA(sha, 13);
ENCODE_ALGORITHMIDENTIFIER_SHA(sha1, 27);
ENCODE_ALGORITHMIDENTIFIER_RFC3279(sha1, 3);
/* dsaWithSHA OIDs are of the form: (2 16 840 1 101 3 4 3 |n|) */
#define ENCODE_ALGORITHMIDENTIFIER_SHAx(name, n) \
/*
* dsaWithSHAx OIDs are of the form: (sigAlgs |n|)
* where sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 }
*/
#define ENCODE_ALGORITHMIDENTIFIER_SIGALGS(name, n) \
static const unsigned char algorithmidentifier_##name##_der[] = { \
ASN1_SEQUENCE, 0x0b, \
ASN1_OID, 0x09, 2 * 40 + 16, 0x86, 0x48, 1, 101, 3, 4, 3, n \
}
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha224, 1);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha256, 2);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha384, 3);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha512, 4);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha3_224, 5);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha3_256, 6);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha3_384, 7);
ENCODE_ALGORITHMIDENTIFIER_SHAx(sha3_512, 8);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha224, 1);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha256, 2);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha384, 3);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha512, 4);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_224, 5);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_256, 6);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_384, 7);
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_512, 8);
#define MD_CASE(name) \
case NID_##name: \
@@ -49,7 +55,6 @@ ENCODE_ALGORITHMIDENTIFIER_SHAx(sha3_512, 8);
const unsigned char *dsa_algorithmidentifier_encoding(int md_nid, size_t *len)
{
switch (md_nid) {
MD_CASE(sha);
MD_CASE(sha1);
MD_CASE(sha224);
MD_CASE(sha256);
+62 -5
View File
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -17,10 +17,12 @@
#include <time.h>
#include "internal/cryptlib.h"
#include <openssl/bn.h>
#include <openssl/self_test.h>
#include "crypto/dsa.h"
#include "dsa_local.h"
static int dsa_builtin_keygen(DSA *dsa);
static int dsa_keygen(DSA *dsa, int pairwise_test);
static int dsa_keygen_pairwise_test(DSA *dsa, OSSL_CALLBACK *cb, void *cbarg);
int DSA_generate_key(DSA *dsa)
{
@@ -28,7 +30,7 @@ int DSA_generate_key(DSA *dsa)
if (dsa->meth->dsa_keygen != NULL)
return dsa->meth->dsa_keygen(dsa);
#endif
return dsa_builtin_keygen(dsa);
return dsa_keygen(dsa, 0);
}
int dsa_generate_public_key(BN_CTX *ctx, const DSA *dsa, const BIGNUM *priv_key,
@@ -50,7 +52,7 @@ err:
return ret;
}
static int dsa_builtin_keygen(DSA *dsa)
static int dsa_keygen(DSA *dsa, int pairwise_test)
{
int ok = 0;
BN_CTX *ctx = NULL;
@@ -82,8 +84,26 @@ static int dsa_builtin_keygen(DSA *dsa)
dsa->priv_key = priv_key;
dsa->pub_key = pub_key;
dsa->dirty_cnt++;
#ifdef FIPS_MODE
pairwise_test = 1;
#endif /* FIPS_MODE */
ok = 1;
if (pairwise_test) {
OSSL_CALLBACK *cb = NULL;
void *cbarg = NULL;
OSSL_SELF_TEST_get_callback(dsa->libctx, &cb, &cbarg);
ok = dsa_keygen_pairwise_test(dsa, cb, cbarg);
if (!ok) {
BN_free(dsa->pub_key);
BN_clear_free(dsa->priv_key);
BN_CTX_free(ctx);
return ok;
}
}
dsa->dirty_cnt++;
err:
if (pub_key != dsa->pub_key)
@@ -91,5 +111,42 @@ static int dsa_builtin_keygen(DSA *dsa)
if (priv_key != dsa->priv_key)
BN_free(priv_key);
BN_CTX_free(ctx);
return ok;
}
/*
* FIPS 140-2 IG 9.9 AS09.33
* Perform a sign/verify operation.
*/
static int dsa_keygen_pairwise_test(DSA *dsa, OSSL_CALLBACK *cb, void *cbarg)
{
int ret = 0;
unsigned char dgst[16] = {0};
unsigned int dgst_len = (unsigned int)sizeof(dgst);
DSA_SIG *sig = NULL;
OSSL_SELF_TEST *st = NULL;
st = OSSL_SELF_TEST_new(cb, cbarg);
if (st == NULL)
goto err;
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_PCT,
OSSL_SELF_TEST_DESC_PCT_DSA);
sig = DSA_do_sign(dgst, (int)dgst_len, dsa);
if (sig == NULL)
goto err;
OSSL_SELF_TEST_oncorrupt_byte(st, dgst);
if (DSA_do_verify(dgst, dgst_len, sig, dsa) != 1)
goto err;
ret = 1;
err:
OSSL_SELF_TEST_onend(st, ret);
OSSL_SELF_TEST_free(st);
DSA_SIG_free(sig);
return ret;
}
+5
View File
@@ -337,3 +337,8 @@ int DSA_bits(const DSA *dsa)
{
return BN_num_bits(dsa->params.p);
}
FFC_PARAMS *dsa_get0_params(DSA *dsa)
{
return &dsa->params;
}