[PATCH 1/3] md: remove hash_buffer function from algorithms
Jussi Kivilinna
jussi.kivilinna at iki.fi
Fri Apr 9 18:53:12 CEST 2021
* cipher/md.c (_gcry_md_hash_buffer): Remove used of
'spec->hash_buffer'.
* cipher/blake2.c (DEFINE_BLAKE2_VARIANT): Remove *_hash_buffer.
* cipher/crc.c: Remove spec hash_buffer NULL pointers.
* cipher/gostr3411-94.c: Remove spec hash_buffer NULL pointers.
* cipher/keccak.c (_gcry_sha3_hash_buffer
(_gcry_sha3_224_hash_buffer, _gcry_sha3_256_hash_buffer): Remove.
(_gcry_sha3_384_hash_buffer, _gcry_sha3_512_hash_buffer): Remove.
* cipher/md2.c: Remove spec hash_buffer NULL pointers.
* cipher/md4.c: Remove spec hash_buffer NULL pointers.
* cipher/md5.c: Remove spec hash_buffer NULL pointers.
* cipher/rmd160.c (_gcry_rmd160_hash_buffer): Remove.
* cipher/sha1.c (_gcry_sha1_hash_buffer): Rewrite using
_gcry_sha1_hash_buffers.
(_gcry_sha1_hash_buffers): Make static.
(_gcry_digest_spec_sha1): Remove hash_buffer pointer.
* cipher/sha256.c (_gcry_sha256_hash_buffer)
(_gcry_sha224_hash_buffer): Remove.
(_gcry_sha256_hash_buffers): Make static.
* cipher/sha512.c (_gcry_sha512_hash_buffer)
(_gcry_sha384_hash_buffer, _gcry_sha512_256_hash_buffer)
(_gcry_sha512_224_hash_buffer): Remove.
(_gcry_sha512_hash_buffers): Make static.
* cipher/sm3.c (_gcry_sm3_hash_buffer): Remove.
(_gcry_sm3_hash_buffers): Make static.
* cipher/stribog.c: Remove spec hash_buffer NULL pointers.
* cipher/tiger.c: Remove spec hash_buffer NULL pointers.
* cipher/whirlpool.c: Remove spec hash_buffer NULL pointers.
* src/cipher-proto.h (gcry_md_hash_buffer_t): Remove.
(gcry_md_spec_t): Remove 'hash_buffer'.
* src/cipher.h (_gcry_rmd160_hash_buffer, _gcry_sha1_hash_buffers)
(_gcry_sha256_hash_buffer, _gcry_sha256_hash_buffers)
(_gcry_sha512_hash_buffer, _gcry_sha512_hash_buffers)
(_gcry_sm3_hash_buffer, _gcry_sm3_hash_buffers): Remove.
--
Patch removes hash_buffer functions and uses hash_buffers instead
for code deduplication.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
cipher/blake2.c | 11 -------
cipher/crc.c | 6 ++--
cipher/gostr3411-94.c | 4 +--
cipher/keccak.c | 51 ++++---------------------------
cipher/md.c | 6 +---
cipher/md2.c | 2 +-
cipher/md4.c | 2 +-
cipher/md5.c | 2 +-
cipher/rmd160.c | 16 ++--------
cipher/sha1.c | 30 +++++++++---------
cipher/sha256.c | 36 +++-------------------
cipher/sha512.c | 71 ++++++-------------------------------------
cipher/sm3.c | 19 ++----------
cipher/stribog.c | 4 +--
cipher/tiger.c | 6 ++--
cipher/whirlpool.c | 2 +-
src/cipher-proto.h | 5 ---
src/cipher.h | 24 ---------------
18 files changed, 56 insertions(+), 241 deletions(-)
diff --git a/cipher/blake2.c b/cipher/blake2.c
index f2bf49e5..0243ed33 100644
--- a/cipher/blake2.c
+++ b/cipher/blake2.c
@@ -946,16 +946,6 @@ gcry_err_code_t _gcry_blake2_init_with_key(void *ctx, unsigned int flags,
gcry_assert (err == 0); \
} \
static void \
- _gcry_blake2##bs##_##dbits##_hash_buffer(void *outbuf, \
- const void *buffer, size_t length) \
- { \
- BLAKE2##BS##_CONTEXT hd; \
- blake2##bs##_##dbits##_init (&hd, 0); \
- blake2##bs##_write (&hd, buffer, length); \
- blake2##bs##_final (&hd); \
- memcpy (outbuf, blake2##bs##_read (&hd), dbits / 8); \
- } \
- static void \
_gcry_blake2##bs##_##dbits##_hash_buffers(void *outbuf, \
const gcry_buffer_t *iov, int iovcnt) \
{ \
@@ -980,7 +970,6 @@ gcry_err_code_t _gcry_blake2_init_with_key(void *ctx, unsigned int flags,
DIM (blake2##bs##_##dbits##_asn), oid_spec_blake2##bs##_##dbits, \
dbits / 8, blake2##bs##_##dbits##_init, blake2##bs##_write, \
blake2##bs##_final, blake2##bs##_read, NULL, \
- _gcry_blake2##bs##_##dbits##_hash_buffer, \
_gcry_blake2##bs##_##dbits##_hash_buffers, \
sizeof (BLAKE2##BS##_CONTEXT), selftests_blake2##bs \
};
diff --git a/cipher/crc.c b/cipher/crc.c
index 6d70f644..db8d8dc9 100644
--- a/cipher/crc.c
+++ b/cipher/crc.c
@@ -932,7 +932,7 @@ gcry_md_spec_t _gcry_digest_spec_crc32 =
GCRY_MD_CRC32, {0, 1},
"CRC32", NULL, 0, NULL, 4,
crc32_init, crc32_write, crc32_final, crc32_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (CRC_CONTEXT)
};
@@ -941,7 +941,7 @@ gcry_md_spec_t _gcry_digest_spec_crc32_rfc1510 =
GCRY_MD_CRC32_RFC1510, {0, 1},
"CRC32RFC1510", NULL, 0, NULL, 4,
crc32rfc1510_init, crc32_write, crc32rfc1510_final, crc32_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (CRC_CONTEXT)
};
@@ -950,6 +950,6 @@ gcry_md_spec_t _gcry_digest_spec_crc24_rfc2440 =
GCRY_MD_CRC24_RFC2440, {0, 1},
"CRC24RFC2440", NULL, 0, NULL, 3,
crc24rfc2440_init, crc24rfc2440_write, crc24rfc2440_final, crc32_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (CRC_CONTEXT)
};
diff --git a/cipher/gostr3411-94.c b/cipher/gostr3411-94.c
index 7cf0637e..588d5dc1 100644
--- a/cipher/gostr3411-94.c
+++ b/cipher/gostr3411-94.c
@@ -370,7 +370,7 @@ gcry_md_spec_t _gcry_digest_spec_gost3411_94 =
GCRY_MD_GOSTR3411_94, {0, 0},
"GOSTR3411_94", NULL, 0, NULL, 32,
gost3411_init, _gcry_md_block_write, gost3411_final, gost3411_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (GOSTR3411_CONTEXT)
};
gcry_md_spec_t _gcry_digest_spec_gost3411_cp =
@@ -378,6 +378,6 @@ gcry_md_spec_t _gcry_digest_spec_gost3411_cp =
GCRY_MD_GOSTR3411_CP, {0, 0},
"GOSTR3411_CP", asn, DIM (asn), oid_spec_gostr3411, 32,
gost3411_cp_init, _gcry_md_block_write, gost3411_final, gost3411_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (GOSTR3411_CONTEXT)
};
diff --git a/cipher/keccak.c b/cipher/keccak.c
index 795a02e5..bb643e3d 100644
--- a/cipher/keccak.c
+++ b/cipher/keccak.c
@@ -1221,21 +1221,6 @@ keccak_extract (void *context, void *out, size_t outlen)
}
-/* Shortcut functions which puts the hash value of the supplied buffer
- * into outbuf which must have a size of 'spec->mdlen' bytes. */
-static void
-_gcry_sha3_hash_buffer (void *outbuf, const void *buffer, size_t length,
- const gcry_md_spec_t *spec)
-{
- KECCAK_CONTEXT hd;
-
- spec->init (&hd, 0);
- keccak_write (&hd, buffer, length);
- keccak_final (&hd);
- memcpy (outbuf, keccak_read (&hd), spec->mdlen);
-}
-
-
/* Variant of the above shortcut function using multiple buffers. */
static void
_gcry_sha3_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt,
@@ -1251,30 +1236,6 @@ _gcry_sha3_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt,
}
-static void
-_gcry_sha3_224_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- _gcry_sha3_hash_buffer (outbuf, buffer, length, &_gcry_digest_spec_sha3_224);
-}
-
-static void
-_gcry_sha3_256_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- _gcry_sha3_hash_buffer (outbuf, buffer, length, &_gcry_digest_spec_sha3_256);
-}
-
-static void
-_gcry_sha3_384_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- _gcry_sha3_hash_buffer (outbuf, buffer, length, &_gcry_digest_spec_sha3_384);
-}
-
-static void
-_gcry_sha3_512_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- _gcry_sha3_hash_buffer (outbuf, buffer, length, &_gcry_digest_spec_sha3_512);
-}
-
static void
_gcry_sha3_224_hash_buffers (void *outbuf, const gcry_buffer_t *iov,
int iovcnt)
@@ -1526,7 +1487,7 @@ gcry_md_spec_t _gcry_digest_spec_sha3_224 =
GCRY_MD_SHA3_224, {0, 1},
"SHA3-224", sha3_224_asn, DIM (sha3_224_asn), oid_spec_sha3_224, 28,
sha3_224_init, keccak_write, keccak_final, keccak_read, NULL,
- _gcry_sha3_224_hash_buffer, _gcry_sha3_224_hash_buffers,
+ _gcry_sha3_224_hash_buffers,
sizeof (KECCAK_CONTEXT),
run_selftests
};
@@ -1535,7 +1496,7 @@ gcry_md_spec_t _gcry_digest_spec_sha3_256 =
GCRY_MD_SHA3_256, {0, 1},
"SHA3-256", sha3_256_asn, DIM (sha3_256_asn), oid_spec_sha3_256, 32,
sha3_256_init, keccak_write, keccak_final, keccak_read, NULL,
- _gcry_sha3_256_hash_buffer, _gcry_sha3_256_hash_buffers,
+ _gcry_sha3_256_hash_buffers,
sizeof (KECCAK_CONTEXT),
run_selftests
};
@@ -1544,7 +1505,7 @@ gcry_md_spec_t _gcry_digest_spec_sha3_384 =
GCRY_MD_SHA3_384, {0, 1},
"SHA3-384", sha3_384_asn, DIM (sha3_384_asn), oid_spec_sha3_384, 48,
sha3_384_init, keccak_write, keccak_final, keccak_read, NULL,
- _gcry_sha3_384_hash_buffer, _gcry_sha3_384_hash_buffers,
+ _gcry_sha3_384_hash_buffers,
sizeof (KECCAK_CONTEXT),
run_selftests
};
@@ -1553,7 +1514,7 @@ gcry_md_spec_t _gcry_digest_spec_sha3_512 =
GCRY_MD_SHA3_512, {0, 1},
"SHA3-512", sha3_512_asn, DIM (sha3_512_asn), oid_spec_sha3_512, 64,
sha3_512_init, keccak_write, keccak_final, keccak_read, NULL,
- _gcry_sha3_512_hash_buffer, _gcry_sha3_512_hash_buffers,
+ _gcry_sha3_512_hash_buffers,
sizeof (KECCAK_CONTEXT),
run_selftests
};
@@ -1562,7 +1523,7 @@ gcry_md_spec_t _gcry_digest_spec_shake128 =
GCRY_MD_SHAKE128, {0, 1},
"SHAKE128", shake128_asn, DIM (shake128_asn), oid_spec_shake128, 0,
shake128_init, keccak_write, keccak_final, NULL, keccak_extract,
- NULL, NULL,
+ NULL,
sizeof (KECCAK_CONTEXT),
run_selftests
};
@@ -1571,7 +1532,7 @@ gcry_md_spec_t _gcry_digest_spec_shake256 =
GCRY_MD_SHAKE256, {0, 1},
"SHAKE256", shake256_asn, DIM (shake256_asn), oid_spec_shake256, 0,
shake256_init, keccak_write, keccak_final, NULL, keccak_extract,
- NULL, NULL,
+ NULL,
sizeof (KECCAK_CONTEXT),
run_selftests
};
diff --git a/cipher/md.c b/cipher/md.c
index 87979059..f142e9c3 100644
--- a/cipher/md.c
+++ b/cipher/md.c
@@ -1205,11 +1205,7 @@ _gcry_md_hash_buffer (int algo, void *digest,
}
}
- if (spec->hash_buffer != NULL)
- {
- spec->hash_buffer (digest, buffer, length);
- }
- else if (spec->hash_buffers != NULL)
+ if (spec->hash_buffers != NULL)
{
gcry_buffer_t iov;
diff --git a/cipher/md2.c b/cipher/md2.c
index dc4deac3..8fc5a6da 100644
--- a/cipher/md2.c
+++ b/cipher/md2.c
@@ -176,6 +176,6 @@ gcry_md_spec_t _gcry_digest_spec_md2 =
GCRY_MD_MD2, {0, 0},
"MD2", asn, DIM (asn), oid_spec_md2, 16,
md2_init, _gcry_md_block_write, md2_final, md2_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (MD2_CONTEXT)
};
diff --git a/cipher/md4.c b/cipher/md4.c
index b55443a8..46aa8681 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -291,6 +291,6 @@ gcry_md_spec_t _gcry_digest_spec_md4 =
GCRY_MD_MD4, {0, 0},
"MD4", asn, DIM (asn), oid_spec_md4,16,
md4_init, _gcry_md_block_write, md4_final, md4_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (MD4_CONTEXT)
};
diff --git a/cipher/md5.c b/cipher/md5.c
index 32cb535a..e98aea52 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -317,6 +317,6 @@ gcry_md_spec_t _gcry_digest_spec_md5 =
GCRY_MD_MD5, {0, 0},
"MD5", asn, DIM (asn), oid_spec_md5, 16,
md5_init, _gcry_md_block_write, md5_final, md5_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (MD5_CONTEXT)
};
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index e12ff017..37462130 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -477,21 +477,9 @@ rmd160_read( void *context )
/****************
- * Shortcut functions which puts the hash value of the supplied buffer
+ * Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 20 bytes.
*/
-void
-_gcry_rmd160_hash_buffer (void *outbuf, const void *buffer, size_t length )
-{
- RMD160_CONTEXT hd;
-
- rmd160_init (&hd, 0);
- _gcry_md_block_write ( &hd, buffer, length );
- rmd160_final ( &hd );
- memcpy ( outbuf, hd.bctx.buf, 20 );
-}
-
-/* Variant of the above shortcut function using a multiple buffers. */
static void
_gcry_rmd160_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
@@ -524,6 +512,6 @@ gcry_md_spec_t _gcry_digest_spec_rmd160 =
GCRY_MD_RMD160, {0, 0},
"RIPEMD160", asn, DIM (asn), oid_spec_rmd160, 20,
rmd160_init, _gcry_md_block_write, rmd160_final, rmd160_read, NULL,
- _gcry_rmd160_hash_buffer, _gcry_rmd160_hash_buffers,
+ _gcry_rmd160_hash_buffers,
sizeof (RMD160_CONTEXT)
};
diff --git a/cipher/sha1.c b/cipher/sha1.c
index 35f7376c..48fdbb33 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -631,34 +631,34 @@ sha1_read( void *context )
return hd->bctx.buf;
}
+
/****************
- * Shortcut functions which puts the hash value of the supplied buffer
+ * Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 20 bytes.
*/
-void
-_gcry_sha1_hash_buffer (void *outbuf, const void *buffer, size_t length)
+static void
+_gcry_sha1_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
SHA1_CONTEXT hd;
sha1_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
+ for (;iovcnt > 0; iov++, iovcnt--)
+ _gcry_md_block_write (&hd,
+ (const char*)iov[0].data + iov[0].off, iov[0].len);
sha1_final (&hd);
memcpy (outbuf, hd.bctx.buf, 20);
}
-
-/* Variant of the above shortcut function using a multiple buffers. */
+/* Variant of the above shortcut function using a single buffer. */
void
-_gcry_sha1_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
+_gcry_sha1_hash_buffer (void *outbuf, const void *buffer, size_t length)
{
- SHA1_CONTEXT hd;
+ gcry_buffer_t iov = { 0 };
- sha1_init (&hd, 0);
- for (;iovcnt > 0; iov++, iovcnt--)
- _gcry_md_block_write (&hd,
- (const char*)iov[0].data + iov[0].off, iov[0].len);
- sha1_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 20);
+ iov.data = (void *)buffer;
+ iov.len = length;
+
+ _gcry_sha1_hash_buffers (outbuf, &iov, 1);
}
@@ -759,7 +759,7 @@ gcry_md_spec_t _gcry_digest_spec_sha1 =
GCRY_MD_SHA1, {0, 1},
"SHA1", asn, DIM (asn), oid_spec_sha1, 20,
sha1_init, _gcry_md_block_write, sha1_final, sha1_read, NULL,
- _gcry_sha1_hash_buffer, _gcry_sha1_hash_buffers,
+ _gcry_sha1_hash_buffers,
sizeof (SHA1_CONTEXT),
run_selftests
};
diff --git a/cipher/sha256.c b/cipher/sha256.c
index 93505891..871615b6 100644
--- a/cipher/sha256.c
+++ b/cipher/sha256.c
@@ -628,22 +628,9 @@ sha256_read (void *context)
}
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 32 bytes. */
-void
-_gcry_sha256_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SHA256_CONTEXT hd;
-
- sha256_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sha256_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 32);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-void
+static void
_gcry_sha256_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
SHA256_CONTEXT hd;
@@ -657,22 +644,9 @@ _gcry_sha256_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
}
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 28 bytes. */
static void
-_gcry_sha224_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SHA256_CONTEXT hd;
-
- sha224_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sha256_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 28);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-static void
_gcry_sha224_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
SHA256_CONTEXT hd;
@@ -841,7 +815,7 @@ gcry_md_spec_t _gcry_digest_spec_sha224 =
GCRY_MD_SHA224, {0, 1},
"SHA224", asn224, DIM (asn224), oid_spec_sha224, 28,
sha224_init, _gcry_md_block_write, sha256_final, sha256_read, NULL,
- _gcry_sha224_hash_buffer, _gcry_sha224_hash_buffers,
+ _gcry_sha224_hash_buffers,
sizeof (SHA256_CONTEXT),
run_selftests
};
@@ -851,7 +825,7 @@ gcry_md_spec_t _gcry_digest_spec_sha256 =
GCRY_MD_SHA256, {0, 1},
"SHA256", asn256, DIM (asn256), oid_spec_sha256, 32,
sha256_init, _gcry_md_block_write, sha256_final, sha256_read, NULL,
- _gcry_sha256_hash_buffer, _gcry_sha256_hash_buffers,
+ _gcry_sha256_hash_buffers,
sizeof (SHA256_CONTEXT),
run_selftests
};
diff --git a/cipher/sha512.c b/cipher/sha512.c
index bc4657a8..a23d5bda 100644
--- a/cipher/sha512.c
+++ b/cipher/sha512.c
@@ -862,22 +862,9 @@ sha512_read (void *context)
}
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 64 bytes. */
-void
-_gcry_sha512_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SHA512_CONTEXT hd;
-
- sha512_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sha512_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 64);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-void
+static void
_gcry_sha512_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
SHA512_CONTEXT hd;
@@ -892,22 +879,9 @@ _gcry_sha512_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 48 bytes. */
static void
-_gcry_sha384_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SHA512_CONTEXT hd;
-
- sha384_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sha512_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 48);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-static void
_gcry_sha384_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
SHA512_CONTEXT hd;
@@ -922,27 +896,15 @@ _gcry_sha384_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 32 bytes. */
static void
-_gcry_sha512_256_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SHA512_CONTEXT hd;
-
- sha512_256_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sha512_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 32);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-static void
_gcry_sha512_256_hash_buffers (void *outbuf, const gcry_buffer_t *iov,
int iovcnt)
{
SHA512_CONTEXT hd;
+
sha512_256_init (&hd, 0);
for (;iovcnt > 0; iov++, iovcnt--)
_gcry_md_block_write (&hd,
@@ -953,22 +915,9 @@ _gcry_sha512_256_hash_buffers (void *outbuf, const gcry_buffer_t *iov,
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 28 bytes. */
static void
-_gcry_sha512_224_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SHA512_CONTEXT hd;
-
- sha512_224_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sha512_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 28);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-static void
_gcry_sha512_224_hash_buffers (void *outbuf, const gcry_buffer_t *iov,
int iovcnt)
{
@@ -1242,7 +1191,7 @@ gcry_md_spec_t _gcry_digest_spec_sha512 =
GCRY_MD_SHA512, {0, 1},
"SHA512", sha512_asn, DIM (sha512_asn), oid_spec_sha512, 64,
sha512_init, _gcry_md_block_write, sha512_final, sha512_read, NULL,
- _gcry_sha512_hash_buffer, _gcry_sha512_hash_buffers,
+ _gcry_sha512_hash_buffers,
sizeof (SHA512_CONTEXT),
run_selftests
};
@@ -1272,7 +1221,7 @@ gcry_md_spec_t _gcry_digest_spec_sha384 =
GCRY_MD_SHA384, {0, 1},
"SHA384", sha384_asn, DIM (sha384_asn), oid_spec_sha384, 48,
sha384_init, _gcry_md_block_write, sha512_final, sha512_read, NULL,
- _gcry_sha384_hash_buffer, _gcry_sha384_hash_buffers,
+ _gcry_sha384_hash_buffers,
sizeof (SHA512_CONTEXT),
run_selftests
};
@@ -1291,7 +1240,7 @@ gcry_md_spec_t _gcry_digest_spec_sha512_256 =
GCRY_MD_SHA512_256, {0, 1},
"SHA512_256", sha512_256_asn, DIM (sha512_256_asn), oid_spec_sha512_256, 32,
sha512_256_init, _gcry_md_block_write, sha512_final, sha512_read, NULL,
- _gcry_sha512_256_hash_buffer, _gcry_sha512_256_hash_buffers,
+ _gcry_sha512_256_hash_buffers,
sizeof (SHA512_CONTEXT),
run_selftests
};
@@ -1310,7 +1259,7 @@ gcry_md_spec_t _gcry_digest_spec_sha512_224 =
GCRY_MD_SHA512_224, {0, 1},
"SHA512_224", sha512_224_asn, DIM (sha512_224_asn), oid_spec_sha512_224, 28,
sha512_224_init, _gcry_md_block_write, sha512_final, sha512_read, NULL,
- _gcry_sha512_224_hash_buffer, _gcry_sha512_224_hash_buffers,
+ _gcry_sha512_224_hash_buffers,
sizeof (SHA512_CONTEXT),
run_selftests
};
diff --git a/cipher/sm3.c b/cipher/sm3.c
index 0f9bae3b..c687cdf0 100644
--- a/cipher/sm3.c
+++ b/cipher/sm3.c
@@ -338,22 +338,9 @@ sm3_read (void *context)
}
-/* Shortcut functions which puts the hash value of the supplied buffer
+/* Shortcut functions which puts the hash value of the supplied buffer iov
* into outbuf which must have a size of 32 bytes. */
-void
-_gcry_sm3_hash_buffer (void *outbuf, const void *buffer, size_t length)
-{
- SM3_CONTEXT hd;
-
- sm3_init (&hd, 0);
- _gcry_md_block_write (&hd, buffer, length);
- sm3_final (&hd);
- memcpy (outbuf, hd.bctx.buf, 32);
-}
-
-
-/* Variant of the above shortcut function using multiple buffers. */
-void
+static void
_gcry_sm3_hash_buffers (void *outbuf, const gcry_buffer_t *iov, int iovcnt)
{
SM3_CONTEXT hd;
@@ -467,7 +454,7 @@ gcry_md_spec_t _gcry_digest_spec_sm3 =
GCRY_MD_SM3, {0, 0},
"SM3", asn_sm3, DIM (asn_sm3), oid_spec_sm3, 32,
sm3_init, _gcry_md_block_write, sm3_final, sm3_read, NULL,
- _gcry_sm3_hash_buffer, _gcry_sm3_hash_buffers,
+ _gcry_sm3_hash_buffers,
sizeof (SM3_CONTEXT),
run_selftests
};
diff --git a/cipher/stribog.c b/cipher/stribog.c
index f8776a3e..e0ee1515 100644
--- a/cipher/stribog.c
+++ b/cipher/stribog.c
@@ -1348,7 +1348,7 @@ gcry_md_spec_t _gcry_digest_spec_stribog_256 =
GCRY_MD_STRIBOG256, {0, 0},
"STRIBOG256", NULL, 0, oid_spec_stribog256, 32,
stribog_init_256, _gcry_md_block_write, stribog_final, stribog_read_256,
- NULL, NULL, NULL,
+ NULL, NULL,
sizeof (STRIBOG_CONTEXT)
};
@@ -1357,6 +1357,6 @@ gcry_md_spec_t _gcry_digest_spec_stribog_512 =
GCRY_MD_STRIBOG512, {0, 0},
"STRIBOG512", NULL, 0, oid_spec_stribog512, 64,
stribog_init_512, _gcry_md_block_write, stribog_final, stribog_read_512,
- NULL, NULL, NULL,
+ NULL, NULL,
sizeof (STRIBOG_CONTEXT)
};
diff --git a/cipher/tiger.c b/cipher/tiger.c
index 4039b22b..f8208ac8 100644
--- a/cipher/tiger.c
+++ b/cipher/tiger.c
@@ -819,7 +819,7 @@ gcry_md_spec_t _gcry_digest_spec_tiger =
GCRY_MD_TIGER, {0, 0},
"TIGER192", NULL, 0, NULL, 24,
tiger_init, _gcry_md_block_write, tiger_final, tiger_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (TIGER_CONTEXT)
};
@@ -843,7 +843,7 @@ gcry_md_spec_t _gcry_digest_spec_tiger1 =
GCRY_MD_TIGER1, {0, 0},
"TIGER", asn1, DIM (asn1), oid_spec_tiger1, 24,
tiger1_init, _gcry_md_block_write, tiger_final, tiger_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (TIGER_CONTEXT)
};
@@ -855,6 +855,6 @@ gcry_md_spec_t _gcry_digest_spec_tiger2 =
GCRY_MD_TIGER2, {0, 0},
"TIGER2", NULL, 0, NULL, 24,
tiger2_init, _gcry_md_block_write, tiger_final, tiger_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (TIGER_CONTEXT)
};
diff --git a/cipher/whirlpool.c b/cipher/whirlpool.c
index 79b2026b..f6e5a7db 100644
--- a/cipher/whirlpool.c
+++ b/cipher/whirlpool.c
@@ -1530,6 +1530,6 @@ gcry_md_spec_t _gcry_digest_spec_whirlpool =
GCRY_MD_WHIRLPOOL, {0, 0},
"WHIRLPOOL", NULL, 0, NULL, 64,
whirlpool_init, whirlpool_write, whirlpool_final, whirlpool_read, NULL,
- NULL, NULL,
+ NULL,
sizeof (whirlpool_context_t)
};
diff --git a/src/cipher-proto.h b/src/cipher-proto.h
index f9fbb553..dde56d30 100644
--- a/src/cipher-proto.h
+++ b/src/cipher-proto.h
@@ -221,10 +221,6 @@ typedef unsigned char *(*gcry_md_read_t) (void *c);
/* Type for the md_extract function. */
typedef void (*gcry_md_extract_t) (void *c, void *outbuf, size_t nbytes);
-/* Type for the md_hash_buffer function. */
-typedef void (*gcry_md_hash_buffer_t) (void *outbuf, const void *buffer,
- size_t length);
-
/* Type for the md_hash_buffers function. */
typedef void (*gcry_md_hash_buffers_t) (void *outbuf, const gcry_buffer_t *iov,
int iovcnt);
@@ -252,7 +248,6 @@ typedef struct gcry_md_spec
gcry_md_final_t final;
gcry_md_read_t read;
gcry_md_extract_t extract;
- gcry_md_hash_buffer_t hash_buffer;
gcry_md_hash_buffers_t hash_buffers;
size_t contextsize; /* allocate this amount of context */
selftest_func_t selftest;
diff --git a/src/cipher.h b/src/cipher.h
index 908e3b78..2efe00fa 100644
--- a/src/cipher.h
+++ b/src/cipher.h
@@ -114,33 +114,9 @@ gcry_err_code_t _gcry_cipher_cmac_check_tag
gcry_err_code_t _gcry_cipher_cmac_set_subkeys
/* */ (gcry_cipher_hd_t c);
-/*-- rmd160.c --*/
-void _gcry_rmd160_hash_buffer (void *outbuf,
- const void *buffer, size_t length);
-
/*-- sha1.c --*/
void _gcry_sha1_hash_buffer (void *outbuf,
const void *buffer, size_t length);
-void _gcry_sha1_hash_buffers (void *outbuf,
- const gcry_buffer_t *iov, int iovcnt);
-
-/*-- sha256.c --*/
-void _gcry_sha256_hash_buffer (void *outbuf,
- const void *buffer, size_t length);
-void _gcry_sha256_hash_buffers (void *outbuf,
- const gcry_buffer_t *iov, int iovcnt);
-
-/*-- sha512.c --*/
-void _gcry_sha512_hash_buffer (void *outbuf,
- const void *buffer, size_t length);
-void _gcry_sha512_hash_buffers (void *outbuf,
- const gcry_buffer_t *iov, int iovcnt);
-
-/*-- sm3.c --*/
-void _gcry_sm3_hash_buffer (void *outbuf,
- const void *buffer, size_t length);
-void _gcry_sm3_hash_buffers (void *outbuf,
- const gcry_buffer_t *iov, int iovcnt);
/*-- blake2.c --*/
gcry_err_code_t _gcry_blake2_init_with_key(void *ctx, unsigned int flags,
--
2.27.0
More information about the Gcrypt-devel
mailing list