diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2014-06-06 22:48:36 +0400 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2014-06-28 10:47:22 +0200 |
commit | 066f068bd0bc4d8e01f1f18b6153cdc8d2c245d7 (patch) | |
tree | 05974f119ff15a72bd0a970d10d667398013e778 /cipher/gost28147.c | |
parent | 7aeba6c449169926076df83b01ddbfa6b41fe411 (diff) | |
download | libgcrypt-066f068bd0bc4d8e01f1f18b6153cdc8d2c245d7.tar.gz |
gostr3411_94: rewrite to use u32 mathematic
* cipher/gost28147.c (_gcry_gost_enc_data): New.
* cipher/gostr3411-94.c: Rewrite implementation to use u32 mathematic
internally.
* cipher/gost28147.c (_gcry_gost_enc_one): Remove.
--
On my box (Core2 Duo, i386) this highly improves GOST R 34.11-94 speed.
Before:
GOSTR3411_94 | 55.04 ns/B 17.33 MiB/s - c/B
After:
GOSTR3411_94 | 36.70 ns/B 25.99 MiB/s - c/B
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'cipher/gost28147.c')
-rw-r--r-- | cipher/gost28147.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/cipher/gost28147.c b/cipher/gost28147.c index af3911ef..4ff80b46 100644 --- a/cipher/gost28147.c +++ b/cipher/gost28147.c @@ -69,13 +69,9 @@ gost_val (GOST28147_context *ctx, u32 cm1, int subkey) } static unsigned int -gost_encrypt_block (void *c, byte *outbuf, const byte *inbuf) +_gost_encrypt_data (void *c, u32 *o1, u32 *o2, u32 n1, u32 n2) { GOST28147_context *ctx = c; - u32 n1, n2; - - n1 = buf_get_le32 (inbuf); - n2 = buf_get_le32 (inbuf+4); n2 ^= gost_val (ctx, n1, 0); n1 ^= gost_val (ctx, n2, 1); n2 ^= gost_val (ctx, n1, 2); n1 ^= gost_val (ctx, n2, 3); @@ -97,23 +93,41 @@ gost_encrypt_block (void *c, byte *outbuf, const byte *inbuf) n2 ^= gost_val (ctx, n1, 3); n1 ^= gost_val (ctx, n2, 2); n2 ^= gost_val (ctx, n1, 1); n1 ^= gost_val (ctx, n2, 0); - buf_put_le32 (outbuf+0, n2); - buf_put_le32 (outbuf+4, n1); + *o1 = n2; + *o2 = n1; return /* burn_stack */ 4*sizeof(void*) /* func call */ + 3*sizeof(void*) /* stack */ + 4*sizeof(void*) /* gost_val call */; } -unsigned int _gcry_gost_enc_one (GOST28147_context *c, const byte *key, - byte *out, byte *in, int cryptopro) +static unsigned int +gost_encrypt_block (void *c, byte *outbuf, const byte *inbuf) +{ + GOST28147_context *ctx = c; + u32 n1, n2; + unsigned int burn; + + n1 = buf_get_le32 (inbuf); + n2 = buf_get_le32 (inbuf+4); + + burn = _gost_encrypt_data(ctx, &n1, &n2, n1, n2); + + buf_put_le32 (outbuf+0, n1); + buf_put_le32 (outbuf+4, n2); + + return /* burn_stack */ burn + 6*sizeof(void*) /* func call */; +} + +unsigned int _gcry_gost_enc_data (GOST28147_context *c, const u32 *key, + u32 *o1, u32 *o2, u32 n1, u32 n2, int cryptopro) { if (cryptopro) c->sbox = sbox_CryptoPro_3411; else c->sbox = sbox_test_3411; - gost_setkey (c, key, 32); - return gost_encrypt_block (c, out, in) + 5 * sizeof(void *); + memcpy (c->key, key, 8*4); + return _gost_encrypt_data (c, o1, o2, n1, n2) + 7 * sizeof(void *); } static unsigned int |