mirror of
https://abf.rosa.ru/djam/libressl.git
synced 2025-02-23 16:12:53 +00:00
100 lines
3.5 KiB
Diff
100 lines
3.5 KiB
Diff
From c982fe656b75adba6c64552d1657b842555cb887 Mon Sep 17 00:00:00 2001
|
|
From: Dmitry Baryshkov <dbaryshkov@gmail.com>
|
|
Date: Mon, 23 Mar 2020 23:58:00 +0300
|
|
Subject: [PATCH 37/87] gost: add support for ACPKM rekeying
|
|
|
|
Add support for ACPKM internal rekeying (RFC 8645).
|
|
|
|
Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
|
|
---
|
|
src/lib/libcrypto/evp/evp.h | 2 ++
|
|
src/lib/libcrypto/gost/gost89_params.c | 38 ++++++++++++++++++++++++++
|
|
src/lib/libcrypto/gost/gost_locl.h | 5 ++++
|
|
3 files changed, 45 insertions(+)
|
|
|
|
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
|
|
index 26e025d09..77b3a4f8e 100644
|
|
--- a/src/lib/libcrypto/evp/evp.h
|
|
+++ b/src/lib/libcrypto/evp/evp.h
|
|
@@ -396,6 +396,8 @@ struct evp_cipher_st {
|
|
#define EVP_CTRL_GCM_SET_IV_INV 0x18
|
|
/* Set the S-BOX NID for GOST ciphers */
|
|
#define EVP_CTRL_GOST_SET_SBOX 0x19
|
|
+/* Set the key meshing section for GOST ciphers */
|
|
+#define EVP_CTRL_GOST_SET_MESHING 0x1a
|
|
|
|
/* GCM TLS constants */
|
|
/* Length of fixed part of IV derived from PRF */
|
|
diff --git a/src/lib/libcrypto/gost/gost89_params.c b/src/lib/libcrypto/gost/gost89_params.c
|
|
index 7365f7a43..e02265389 100644
|
|
--- a/src/lib/libcrypto/gost/gost89_params.c
|
|
+++ b/src/lib/libcrypto/gost/gost89_params.c
|
|
@@ -50,6 +50,7 @@
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
+#include <string.h>
|
|
|
|
#include <openssl/opensslconf.h>
|
|
|
|
@@ -259,4 +260,41 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_key_mesh(void *ctx,
|
|
+ acpkm_block *block, acpkm_set_key *set_key,
|
|
+ unsigned int block_size, unsigned int key_size)
|
|
+{
|
|
+ unsigned int i;
|
|
+ unsigned char new_key[ACPKM_KEY_SIZE];
|
|
+
|
|
+ for (i = 0; i < key_size; i += block_size) {
|
|
+ block(&acpkm_mesh_data[i], &new_key[i], ctx);
|
|
+ }
|
|
+ set_key(ctx, new_key);
|
|
+ explicit_bzero(new_key, i);
|
|
+}
|
|
#endif
|
|
diff --git a/src/lib/libcrypto/gost/gost_locl.h b/src/lib/libcrypto/gost/gost_locl.h
|
|
index 302a19c5c..f512029e1 100644
|
|
--- a/src/lib/libcrypto/gost/gost_locl.h
|
|
+++ b/src/lib/libcrypto/gost/gost_locl.h
|
|
@@ -97,6 +97,11 @@ extern void Gost2814789_encrypt(const unsigned char *in, unsigned char *out,
|
|
extern void Gost2814789_decrypt(const unsigned char *in, unsigned char *out,
|
|
const GOST2814789_KEY *key);
|
|
extern void Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key);
|
|
+typedef void acpkm_block(const unsigned char *in, unsigned char *out, void *ctx);
|
|
+typedef void acpkm_set_key(void *ctx, const unsigned char *key);
|
|
+extern void acpkm_key_mesh(void *ctx,
|
|
+ acpkm_block *block, acpkm_set_key *set_key,
|
|
+ unsigned int block_size, unsigned int key_size);
|
|
|
|
void Magma_set_key_int(MAGMA_KEY *key, const unsigned char *userKey);
|
|
|
|
--
|
|
2.17.1
|
|
|