[openssl-commits] [openssl] master update
Matt Caswell
matt at openssl.org
Mon Sep 21 09:37:25 UTC 2015
The branch master has been updated
via 7788638777934141e235d0add9341e852ac4e80b (commit)
via eeb1c3976cf4a1746367808e351c0ed7ce21808b (commit)
from bf95cde28712cfcad90cb3975cdcb8e5c0f20fde (commit)
- Log -----------------------------------------------------------------
commit 7788638777934141e235d0add9341e852ac4e80b
Author: Matt Caswell <matt at openssl.org>
Date: Wed Sep 2 11:27:31 2015 +0100
GOST PKCS12 support
Changes required to add GOST support to PKCS12
Based on a patch provided by Dmitry Belyavsky <beldmit at gmail.com>
Reviewed-by: Stephen Henson <steve at openssl.org>
commit eeb1c3976cf4a1746367808e351c0ed7ce21808b
Author: Matt Caswell <matt at openssl.org>
Date: Wed Sep 2 10:55:57 2015 +0100
Add GOST extensions to PKCS#5
GOST extends PKCS5 PBES2/PBKDF2 with some additional GOST specific PRFs.
Based on a patch provided by Dmitry Belyavsky <beldmit at gmail.com>
Reviewed-by: Stephen Henson <steve at openssl.org>
-----------------------------------------------------------------------
Summary of changes:
crypto/evp/evp_pbe.c | 4 ++++
crypto/pkcs12/p12_mutl.c | 41 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c
index 6172d95..fb7947e 100644
--- a/crypto/evp/evp_pbe.c
+++ b/crypto/evp/evp_pbe.c
@@ -118,6 +118,10 @@ static const EVP_PBE_CTL builtin_pbe[] = {
{EVP_PBE_TYPE_PRF, NID_hmacWithSHA384, -1, NID_sha384, 0},
{EVP_PBE_TYPE_PRF, NID_hmacWithSHA512, -1, NID_sha512, 0},
{EVP_PBE_TYPE_PRF, NID_id_HMACGostR3411_94, -1, NID_id_GostR3411_94, 0},
+ {EVP_PBE_TYPE_PRF, NID_id_tc26_hmac_gost_3411_2012_256, -1,
+ NID_id_GostR3411_2012_256, 0},
+ {EVP_PBE_TYPE_PRF, NID_id_tc26_hmac_gost_3411_2012_512, -1,
+ NID_id_GostR3411_2012_512, 0},
{EVP_PBE_TYPE_KDF, NID_id_pbkdf2, -1, -1, PKCS5_v2_PBKDF2_keyivgen},
#ifndef OPENSSL_NO_SCRYPT
{EVP_PBE_TYPE_KDF, NID_id_scrypt, -1, -1, PKCS5_v2_scrypt_keyivgen}
diff --git a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c
index 9382b39..9da65fe 100644
--- a/crypto/pkcs12/p12_mutl.c
+++ b/crypto/pkcs12/p12_mutl.c
@@ -64,6 +64,28 @@
# include <openssl/rand.h>
# include <openssl/pkcs12.h>
+# define TK26_MAC_KEY_LEN 32
+
+static int pkcs12_gen_gost_mac_key(const char *pass, int passlen,
+ const unsigned char *salt, int saltlen,
+ int iter, int keylen, unsigned char *key,
+ const EVP_MD *digest)
+{
+ unsigned char out[96];
+
+ if (keylen != TK26_MAC_KEY_LEN) {
+ return 0;
+ }
+
+ if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter,
+ digest, sizeof(out), out)) {
+ return 0;
+ }
+ memcpy(key, out + sizeof(out) - TK26_MAC_KEY_LEN, TK26_MAC_KEY_LEN);
+ OPENSSL_cleanse(out, sizeof(out));
+ return 1;
+}
+
/* Generate a MAC */
int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
unsigned char *mac, unsigned int *maclen)
@@ -72,7 +94,8 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
HMAC_CTX hmac;
unsigned char key[EVP_MAX_MD_SIZE], *salt;
int saltlen, iter;
- int md_size;
+ int md_size = 0;
+ int md_type_nid;
if (!PKCS7_type_is_data(p12->authsafes)) {
PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_CONTENT_TYPE_NOT_DATA);
@@ -91,10 +114,22 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
return 0;
}
md_size = EVP_MD_size(md_type);
+ md_type_nid = EVP_MD_type(md_type);
if (md_size < 0)
return 0;
- if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
- md_size, key, md_type)) {
+ if ((md_type_nid == NID_id_GostR3411_94
+ || md_type_nid == NID_id_GostR3411_2012_256
+ || md_type_nid == NID_id_GostR3411_2012_512)
+ && !getenv("LEGACY_GOST_PKCS12")) {
+ md_size = TK26_MAC_KEY_LEN;
+ if (!pkcs12_gen_gost_mac_key(pass, passlen, salt, saltlen, iter,
+ md_size, key, md_type)) {
+ PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_KEY_GEN_ERROR);
+ return 0;
+ }
+ } else
+ if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
+ md_size, key, md_type)) {
PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_KEY_GEN_ERROR);
return 0;
}
More information about the openssl-commits
mailing list