summaryrefslogtreecommitdiff
path: root/cipher/gost28147.c
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2014-06-06 22:48:31 +0400
committerWerner Koch <wk@gnupg.org>2014-06-28 10:42:35 +0200
commit5ee35a04362c94e680ef3633fa83b72e0aee8626 (patch)
treedba5dbfb5b18206d9a45e2b8243f5f257ee31fad /cipher/gost28147.c
parentfb074d113fcbf66a5c20592625cb19051f3430f5 (diff)
downloadlibgcrypt-5ee35a04362c94e680ef3633fa83b72e0aee8626.tar.gz
gost28147: support GCRYCTL_SET_SBOX
cipher/gost28147.c (gost_set_extra_info, gost_set_sbox): New. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'cipher/gost28147.c')
-rw-r--r--cipher/gost28147.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/cipher/gost28147.c b/cipher/gost28147.c
index 1720f45f..ae9e705a 100644
--- a/cipher/gost28147.c
+++ b/cipher/gost28147.c
@@ -175,6 +175,44 @@ gost_decrypt_block (void *c, byte *outbuf, const byte *inbuf)
4*sizeof(void*) /* gost_val call */;
}
+static gpg_err_code_t
+gost_set_sbox (GOST28147_context *ctx, const char *oid)
+{
+ int i;
+
+ for (i = 0; gost_oid_map[i].oid; i++)
+ {
+ if (!strcmp(gost_oid_map[i].oid, oid))
+ {
+ ctx->sbox = gost_oid_map[i].sbox;
+ return 0;
+ }
+ }
+ return GPG_ERR_VALUE_NOT_FOUND;
+}
+
+static gpg_err_code_t
+gost_set_extra_info (void *c, int what, const void *buffer, size_t buflen)
+{
+ GOST28147_context *ctx = c;
+ gpg_err_code_t ec = 0;
+
+ (void)buffer;
+ (void)buflen;
+
+ switch (what)
+ {
+ case GCRYCTL_SET_SBOX:
+ ec = gost_set_sbox (ctx, buffer);
+ break;
+
+ default:
+ ec = GPG_ERR_INV_OP;
+ break;
+ }
+ return ec;
+}
+
static gcry_cipher_oid_spec_t oids_gost28147[] =
{
/* { "1.2.643.2.2.31.0", GCRY_CIPHER_MODE_CNTGOST }, */
@@ -193,4 +231,5 @@ gcry_cipher_spec_t _gcry_cipher_spec_gost28147 =
gost_setkey,
gost_encrypt_block,
gost_decrypt_block,
+ NULL, NULL, NULL, gost_set_extra_info,
};