[PATCH 2/3] Add a function to retrieve algorithm used by MAC handler
Dmitry Eremin-Solenikov
dbaryshkov at gmail.com
Fri Dec 27 09:37:11 CET 2013
* cipher/mac.c (_gcry_mac_get_algo): New function, returns used algo.
* src/visibility.c (gcry_mac_get_algo): New wrapper.
* src/visibility.h: Hanlde gcry_mac_get_algo.
* src/gcrypt-int.h (_gcry_mac_get_algo): New.
* src/gcrypt.h.in (gcry_mac_get_algo): New.
* src/libgcrypt.def (gcry_mac_get_algo): New.
* src/libgcrypt.vers (gcry_mac_get_algo): New.
* doc/gcrypt.texi: Document gcry_mac_get_algo.
* tests/basic.c (check_one_mac): Verify gcry_mac_get_algo.
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
---
cipher/mac.c | 7 +++++++
doc/gcrypt.texi | 10 ++++++++++
src/gcrypt-int.h | 1 +
src/gcrypt.h.in | 3 +++
src/libgcrypt.def | 1 +
src/libgcrypt.vers | 2 +-
src/visibility.c | 6 ++++++
src/visibility.h | 2 ++
tests/basic.c | 6 ++++++
9 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/cipher/mac.c b/cipher/mac.c
index fa36c7d..e675b49 100644
--- a/cipher/mac.c
+++ b/cipher/mac.c
@@ -369,6 +369,13 @@ _gcry_mac_verify (gcry_mac_hd_t hd, const void *buf, size_t buflen)
}
+int
+_gcry_mac_get_algo (gcry_mac_hd_t hd)
+{
+ return hd->algo;
+}
+
+
unsigned int
_gcry_mac_get_algo_maclen (int algo)
{
diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi
index 405c8fe..bb081da 100644
--- a/doc/gcrypt.texi
+++ b/doc/gcrypt.texi
@@ -3728,6 +3728,16 @@ the MAC calculated in object @var{h}.
@end deftypefun
+In some situations it might be hard to remember the algorithm used for
+the MAC calculation. The following function might be used to get that
+information:
+
+ at deftypefun {int} gcry_mac_get_algo (gcry_mac_hd_t @var{h})
+
+Retrieve the algorithm used with the handle @var{h}.
+ at end deftypefun
+
+
@c ***********************************
@c ***** MAC info functions **********
@c ***********************************
diff --git a/src/gcrypt-int.h b/src/gcrypt-int.h
index 65dcb4d..8a6df84 100644
--- a/src/gcrypt-int.h
+++ b/src/gcrypt-int.h
@@ -180,6 +180,7 @@ gpg_err_code_t _gcry_mac_write (gcry_mac_hd_t hd, const void *buffer,
gpg_err_code_t _gcry_mac_read (gcry_mac_hd_t hd, void *buffer, size_t *buflen);
gpg_err_code_t _gcry_mac_verify (gcry_mac_hd_t hd, const void *buffer,
size_t buflen);
+int _gcry_mac_get_algo (gcry_mac_hd_t hd);
unsigned int _gcry_mac_get_algo_maclen (int algo);
unsigned int _gcry_mac_get_algo_keylen (int algo);
const char *_gcry_mac_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index bfb1338..23195af 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -1383,6 +1383,9 @@ gcry_error_t gcry_mac_read (gcry_mac_hd_t hd, void *buffer, size_t *buflen);
gcry_error_t gcry_mac_verify (gcry_mac_hd_t hd, const void *buffer,
size_t buflen);
+/* Retrieve the algorithm used with MAC. */
+int gcry_mac_get_algo (gcry_mac_hd_t hd);
+
/* Retrieve the length in bytes of the MAC yielded by algorithm ALGO. */
unsigned int gcry_mac_get_algo_maclen (int algo);
diff --git a/src/libgcrypt.def b/src/libgcrypt.def
index a90efce..57ed490 100644
--- a/src/libgcrypt.def
+++ b/src/libgcrypt.def
@@ -274,6 +274,7 @@ EXPORTS
gcry_mac_read @240
gcry_mac_verify @241
gcry_mac_ctl @242
+ gcry_mac_get_algo @243
;; end of file with public symbols for Windows.
diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers
index 5118c81..7ee0541 100644
--- a/src/libgcrypt.vers
+++ b/src/libgcrypt.vers
@@ -54,7 +54,7 @@ GCRYPT_1.6 {
gcry_cipher_authenticate; gcry_cipher_gettag; gcry_cipher_checktag;
gcry_mac_algo_info; gcry_mac_algo_name; gcry_mac_map_name;
- gcry_mac_get_algo_maclen; gcry_mac_get_algo_keylen;
+ gcry_mac_get_algo_maclen; gcry_mac_get_algo_keylen; gcry_mac_get_algo;
gcry_mac_open; gcry_mac_close; gcry_mac_setkey; gcry_mac_setiv;
gcry_mac_write; gcry_mac_read; gcry_mac_verify; gcry_mac_ctl;
diff --git a/src/visibility.c b/src/visibility.c
index 2989498..6ed57ca 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -855,6 +855,12 @@ gcry_mac_map_name (const char *string)
return _gcry_mac_map_name (string);
}
+int
+gcry_mac_get_algo (gcry_mac_hd_t hd)
+{
+ return _gcry_mac_get_algo (hd);
+}
+
unsigned int
gcry_mac_get_algo_maclen (int algo)
{
diff --git a/src/visibility.h b/src/visibility.h
index 4127a43..96b5235 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -137,6 +137,7 @@ MARK_VISIBLEX (gcry_cipher_open)
MARK_VISIBLEX (gcry_mac_algo_info)
MARK_VISIBLEX (gcry_mac_algo_name)
MARK_VISIBLEX (gcry_mac_map_name)
+MARK_VISIBLEX (gcry_mac_get_algo)
MARK_VISIBLEX (gcry_mac_get_algo_maclen)
MARK_VISIBLEX (gcry_mac_get_algo_keylen)
MARK_VISIBLEX (gcry_mac_open)
@@ -380,6 +381,7 @@ MARK_VISIBLEX (_gcry_mpi_get_const)
#define gcry_mac_algo_info _gcry_USE_THE_UNDERSCORED_FUNCTION
#define gcry_mac_algo_name _gcry_USE_THE_UNDERSCORED_FUNCTION
#define gcry_mac_map_name _gcry_USE_THE_UNDERSCORED_FUNCTION
+#define gcry_mac_get_algo _gcry_USE_THE_UNDERSCORED_FUNCTION
#define gcry_mac_get_algo_maclen _gcry_USE_THE_UNDERSCORED_FUNCTION
#define gcry_mac_get_algo_keylen _gcry_USE_THE_UNDERSCORED_FUNCTION
#define gcry_mac_open _gcry_USE_THE_UNDERSCORED_FUNCTION
diff --git a/tests/basic.c b/tests/basic.c
index 517daa2..80a9c86 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -4707,6 +4707,12 @@ check_one_mac (int algo, const char *data, int datalen,
return;
}
+ i = gcry_mac_get_algo (hd);
+ if (i != algo)
+ {
+ fail ("algo %d, gcry_mac_get_algo failed: %d\n", algo, i);
+ }
+
maclen = gcry_mac_get_algo_maclen (algo);
if (maclen < 1 || maclen > 500)
{
--
1.8.5.1
More information about the Gcrypt-devel
mailing list