Latest update.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
$SERIALIZER_GOAL=../../libimplementations.a
|
||||
$RSA_GOAL=../../libimplementations.a
|
||||
$FFC_GOAL=../../libimplementations.a
|
||||
$DH_GOAL=../../libimplementations.a
|
||||
$DSA_GOAL=../../libimplementations.a
|
||||
$ECX_GOAL=../../libimplementations.a
|
||||
@@ -10,6 +11,9 @@ $EC_GOAL=../../libimplementations.a
|
||||
|
||||
SOURCE[$SERIALIZER_GOAL]=serializer_common.c
|
||||
SOURCE[$RSA_GOAL]=serializer_rsa.c serializer_rsa_priv.c serializer_rsa_pub.c
|
||||
IF[{- !$disabled{"dh"} || !$disabled{"dsa"} -}]
|
||||
SOURCE[$FFC_GOAL]=serializer_ffc_params.c
|
||||
ENDIF
|
||||
IF[{- !$disabled{dh} -}]
|
||||
SOURCE[$DH_GOAL]=serializer_dh.c serializer_dh_priv.c serializer_dh_pub.c serializer_dh_param.c
|
||||
ENDIF
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/x509.h> /* i2d_X509_PUBKEY_bio() */
|
||||
#include "crypto/bn.h" /* bn_get_words() */
|
||||
#include "crypto/ctype.h"
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h" /* ossl_prov_bio_printf() */
|
||||
#include "prov/implementations.h"
|
||||
@@ -161,11 +162,13 @@ OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_import(const OSSL_DISPATCH *fns
|
||||
int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
const BIGNUM *bn)
|
||||
{
|
||||
const char *neg;
|
||||
int ret = 0, use_sep = 0;
|
||||
char *hex_str = NULL, *p;
|
||||
const char spaces[] = " ";
|
||||
const char *post_label_spc = " ";
|
||||
|
||||
const char *neg = "";
|
||||
int bytes;
|
||||
BN_ULONG *words;
|
||||
int n, i;
|
||||
|
||||
if (bn == NULL)
|
||||
return 0;
|
||||
@@ -174,74 +177,63 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
post_label_spc = "";
|
||||
}
|
||||
|
||||
bytes = BN_num_bytes(bn);
|
||||
words = bn_get_words(bn);
|
||||
neg = BN_is_negative(bn) ? "-" : "";
|
||||
|
||||
if (BN_is_zero(bn))
|
||||
return ossl_prov_bio_printf(out, "%s%s0\n", label, post_label_spc);
|
||||
|
||||
if (BN_num_bytes(bn) <= BN_BYTES)
|
||||
if (BN_num_bytes(bn) <= BN_BYTES) {
|
||||
BN_ULONG *words = bn_get_words(bn);
|
||||
|
||||
if (BN_is_negative(bn))
|
||||
neg = "-";
|
||||
|
||||
return ossl_prov_bio_printf(out,
|
||||
"%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
|
||||
label, post_label_spc, neg, words[0],
|
||||
neg, words[0]);
|
||||
}
|
||||
|
||||
if (neg[0] == '-')
|
||||
hex_str = BN_bn2hex(bn);
|
||||
p = hex_str;
|
||||
if (*p == '-') {
|
||||
++p;
|
||||
neg = " (Negative)";
|
||||
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "%s%s\n", label, neg) <= 0)
|
||||
return 0;
|
||||
goto err;
|
||||
|
||||
/* Keep track of how many bytes we have printed out so far */
|
||||
n = 0;
|
||||
bytes = 0;
|
||||
|
||||
/*
|
||||
* OpenSSL BIGNUMs are little endian limbs, so we print them last to
|
||||
* first limb.
|
||||
* i is used as limb index, j is used as the "byte index" in the limb
|
||||
*/
|
||||
for (i = bytes / BN_BYTES - 1; i >= 0; i--) {
|
||||
BN_ULONG l = words[i];
|
||||
int j;
|
||||
if (ossl_prov_bio_printf(out, "%s", spaces) <= 0)
|
||||
goto err;
|
||||
|
||||
for (j = BN_BYTES - 1; j >= 0; j--) {
|
||||
int o = 8 * j;
|
||||
int b = ((l & (0xffLU << o)) >> o) & 0xff;
|
||||
|
||||
/* Indent every new line with 4 spaces */
|
||||
if ((n % 15) == 0) {
|
||||
if (n > 0)
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
if (ossl_prov_bio_printf(out, " ") <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Upper bit set, then we print an extra zero and pretend the
|
||||
* BIGNUM was one byte longer
|
||||
*/
|
||||
if (n == 0 && b > 127) {
|
||||
if (ossl_prov_bio_printf(out, "%02x:", 0) <= 0)
|
||||
return 0;
|
||||
n++;
|
||||
bytes++;
|
||||
}
|
||||
|
||||
if (++n < bytes) {
|
||||
if (ossl_prov_bio_printf(out, "%02x:", b) <= 0)
|
||||
return 0;
|
||||
} else {
|
||||
if (ossl_prov_bio_printf(out, "%02x", b) <= 0)
|
||||
return 0;
|
||||
}
|
||||
/* Add a leading 00 if the top bit is set */
|
||||
if (*p >= '8') {
|
||||
if (ossl_prov_bio_printf(out, "%02x", 0) <= 0)
|
||||
goto err;
|
||||
++bytes;
|
||||
use_sep = 1;
|
||||
}
|
||||
while (*p != '\0') {
|
||||
/* Do a newline after every 15 hex bytes + add the space indent */
|
||||
if ((bytes % 15) == 0 && bytes > 0) {
|
||||
if (ossl_prov_bio_printf(out, ":\n%s", spaces) <= 0)
|
||||
goto err;
|
||||
use_sep = 0; /* The first byte on the next line doesnt have a : */
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "%s%c%c", use_sep ? ":" : "",
|
||||
ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
|
||||
goto err;
|
||||
++bytes;
|
||||
p += 2;
|
||||
use_sep = 1;
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
OPENSSL_free(hex_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Number of octets per line */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
@@ -13,11 +13,12 @@
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/err.h>
|
||||
#include "prov/bio.h" /* ossl_prov_bio_printf() */
|
||||
#include "prov/implementations.h" /* rsa_keymgmt_functions */
|
||||
#include "prov/providercommonerr.h" /* PROV_R_BN_ERROR */
|
||||
#include "internal/ffc.h"
|
||||
#include "crypto/dh.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dh_new(void)
|
||||
@@ -39,8 +40,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
|
||||
{
|
||||
const char *type_label = NULL;
|
||||
const BIGNUM *priv_key = NULL, *pub_key = NULL;
|
||||
const BIGNUM *p = NULL, *g = NULL;
|
||||
|
||||
const BIGNUM *p = NULL;
|
||||
|
||||
switch (type) {
|
||||
case dh_print_priv:
|
||||
@@ -67,35 +67,19 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
|
||||
}
|
||||
|
||||
p = DH_get0_p(dh);
|
||||
g = DH_get0_g(dh);
|
||||
if (p == NULL || g == NULL)
|
||||
if (p == NULL)
|
||||
goto null_err;
|
||||
|
||||
/*
|
||||
* TODO(3.0): add printing of:
|
||||
*
|
||||
* - q (label "subgroup order:")
|
||||
* - j (label "subgroup factor:")
|
||||
* - seed (label "seed:")
|
||||
* - counter (label "counter:")
|
||||
*
|
||||
* This can happen as soon as there are DH_get0_ functions for them.
|
||||
*/
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
|
||||
<= 0)
|
||||
goto err;
|
||||
if (priv_key != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, " private-key:", priv_key))
|
||||
&& !ossl_prov_print_labeled_bignum(out, "private-key:", priv_key))
|
||||
goto err;
|
||||
if (pub_key != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, " public-key:", pub_key))
|
||||
&& !ossl_prov_print_labeled_bignum(out, "public-key:", pub_key))
|
||||
goto err;
|
||||
if (p != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, " prime:", p))
|
||||
goto err;
|
||||
if (g != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, " generator:", g))
|
||||
if (!ffc_params_prov_print(out, dh_get0_params(dh)))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "prov/implementations.h" /* rsa_keymgmt_functions */
|
||||
#include "prov/providercommonerr.h" /* PROV_R_BN_ERROR */
|
||||
#include "serializer_local.h"
|
||||
#include "internal/ffc.h"
|
||||
#include "crypto/dsa.h"
|
||||
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_dsa_new(void)
|
||||
{
|
||||
@@ -39,7 +41,7 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
|
||||
{
|
||||
const char *type_label = NULL;
|
||||
const BIGNUM *priv_key = NULL, *pub_key = NULL;
|
||||
const BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
const BIGNUM *p = NULL;
|
||||
|
||||
|
||||
switch (type) {
|
||||
@@ -66,15 +68,13 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
|
||||
goto null_err;
|
||||
}
|
||||
|
||||
p = DSA_get0_p(dsa);
|
||||
q = DSA_get0_q(dsa);
|
||||
g = DSA_get0_p(dsa);
|
||||
|
||||
if (p == NULL || q == NULL || g == NULL)
|
||||
p = DSA_get0_p(dsa);
|
||||
if (p == NULL)
|
||||
goto null_err;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
|
||||
<= 0)
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
|
||||
BN_num_bits(p)) <= 0)
|
||||
goto err;
|
||||
if (priv_key != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, "priv:", priv_key))
|
||||
@@ -82,11 +82,7 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
|
||||
if (pub_key != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, "pub: ", pub_key))
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, "P: ", p))
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, "Q: ", q))
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, "G: ", g))
|
||||
if (!ffc_params_prov_print(out, dsa_get0_params(dsa)))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 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
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* Utility function for printing DSA/DH params. */
|
||||
|
||||
#include "prov/bio.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
{
|
||||
if (ffc->nid != NID_undef) {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
const char *name = ffc_named_group_from_uid(ffc->nid);
|
||||
|
||||
if (name == NULL)
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
goto err;
|
||||
return 1;
|
||||
#else
|
||||
/* How could this be? We should not have a nid in a no-dh build. */
|
||||
goto err;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!ossl_prov_print_labeled_bignum(out, "P: ", ffc->p))
|
||||
goto err;
|
||||
if (ffc->q != NULL) {
|
||||
if (!ossl_prov_print_labeled_bignum(out, "Q: ", ffc->q))
|
||||
goto err;
|
||||
}
|
||||
if (!ossl_prov_print_labeled_bignum(out, "G: ", ffc->g))
|
||||
goto err;
|
||||
if (ffc->j != NULL) {
|
||||
if (!ossl_prov_print_labeled_bignum(out, "J: ", ffc->j))
|
||||
goto err;
|
||||
}
|
||||
if (ffc->seed != NULL) {
|
||||
if (!ossl_prov_print_labeled_buf(out, "SEED:", ffc->seed, ffc->seedlen))
|
||||
goto err;
|
||||
}
|
||||
if (ffc->gindex != -1) {
|
||||
if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->pcounter != -1) {
|
||||
if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->h != 0) {
|
||||
if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
goto err;
|
||||
}
|
||||
return 1;
|
||||
err:
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <openssl/x509.h> /* X509_SIG */
|
||||
#include <openssl/types.h>
|
||||
#include <crypto/ecx.h>
|
||||
#include "internal/ffc.h"
|
||||
|
||||
struct pkcs8_encrypt_ctx_st {
|
||||
/* Set to 1 if intending to encrypt/decrypt, otherwise 0 */
|
||||
@@ -54,6 +55,7 @@ int ossl_prov_prepare_ec_params(const void *eckey, int nid,
|
||||
int ossl_prov_ec_pub_to_der(const void *eckey, unsigned char **pder);
|
||||
int ossl_prov_ec_priv_to_der(const void *eckey, unsigned char **pder);
|
||||
|
||||
int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc);
|
||||
int ossl_prov_prepare_dh_params(const void *dh, int nid,
|
||||
void **pstr, int *pstrtype);
|
||||
int ossl_prov_dh_pub_to_der(const void *dh, unsigned char **pder);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-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
|
||||
|
||||
Reference in New Issue
Block a user