...
 
Commits (2)
......@@ -3,8 +3,11 @@
From Dmitry Eremin-Solenikov:
* cmac64.c (_cmac64_block_mulx, cmac64_set_key, cmac64_init)
(cmac64_update, cmac64_digest): New file, new functions.
* cmac.h: Add cmac64 declarations.
* Makefile.in (nettle_SOURCES): Add cmac64.c.
* cmac-des3.c (cmac_des3_set_key, cmac_des3_update)
(cmac_des3_digest): New file, new functions.
* cmac.h: Add cmac64 and cmac_des3 declarations.
* Makefile.in (nettle_SOURCES): Add cmac64.c and cmac-des3.c.
* testsuite/cmac-test.c (test_main): Add tests for cmac_des3.
2019-07-02 Niels Möller <nisse@lysator.liu.se>
......
......@@ -102,7 +102,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
gcm-aes256.c gcm-aes256-meta.c \
gcm-camellia128.c gcm-camellia128-meta.c \
gcm-camellia256.c gcm-camellia256-meta.c \
cmac.c cmac64.c cmac-aes128.c cmac-aes256.c \
cmac.c cmac64.c cmac-aes128.c cmac-aes256.c cmac-des3.c \
gosthash94.c gosthash94-meta.c \
hmac.c hmac-md5.c hmac-ripemd160.c hmac-sha1.c \
hmac-sha224.c hmac-sha256.c hmac-sha384.c hmac-sha512.c \
......
/* cmac-des3.c
CMAC using TrippleDES as the underlying cipher.
Copyright (C) 2019 Dmitry Eremin-Solenikov
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "cmac.h"
void
cmac_des3_set_key (struct cmac_des3_ctx *ctx, const uint8_t *key)
{
CMAC64_SET_KEY (ctx, des3_set_key, des3_encrypt, key);
}
void
cmac_des3_update (struct cmac_des3_ctx *ctx,
size_t length, const uint8_t *data)
{
CMAC64_UPDATE (ctx, des3_encrypt, length, data);
}
void
cmac_des3_digest (struct cmac_des3_ctx *ctx,
size_t length, uint8_t *digest)
{
CMAC64_DIGEST (ctx, des3_encrypt, length, digest);
}
......@@ -37,6 +37,7 @@
#define NETTLE_CMAC_H_INCLUDED
#include "aes.h"
#include "des.h"
#include "nettle-types.h"
#ifdef __cplusplus
......@@ -61,6 +62,9 @@ extern "C" {
#define cmac64_init nettle_cmac64_init
#define cmac64_update nettle_cmac64_update
#define cmac64_digest nettle_cmac64_digest
#define cmac_des3_set_key nettle_cmac_des3_set_key
#define cmac_des3_update nettle_cmac_des3_update
#define cmac_des3_digest nettle_cmac_des3_digest
struct cmac128_key
{
......@@ -213,6 +217,19 @@ void
cmac_aes256_digest(struct cmac_aes256_ctx *ctx,
size_t length, uint8_t *digest);
struct cmac_des3_ctx CMAC64_CTX(struct des3_ctx);
void
cmac_des3_set_key(struct cmac_des3_ctx *ctx, const uint8_t *key);
void
cmac_des3_update(struct cmac_des3_ctx *ctx,
size_t length, const uint8_t *data);
void
cmac_des3_digest(struct cmac_des3_ctx *ctx,
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
......
......@@ -26,12 +26,27 @@ const struct nettle_mac nettle_cmac_aes256 =
(nettle_hash_digest_func*) cmac_aes256_digest
};
const struct nettle_mac nettle_cmac_des3 =
{
"CMAC-3DES",
sizeof(struct cmac_des3_ctx),
CMAC64_DIGEST_SIZE,
DES3_KEY_SIZE,
(nettle_set_key_func*) cmac_des3_set_key,
(nettle_hash_update_func*) cmac_des3_update,
(nettle_hash_digest_func*) cmac_des3_digest
};
#define test_cmac_aes128(key, msg, ref) \
test_mac(&nettle_cmac_aes128, key, msg, ref)
#define test_cmac_aes256(key, msg, ref) \
test_mac(&nettle_cmac_aes256, key, msg, ref)
#define test_cmac_des3(key, msg, ref) \
test_mac(&nettle_cmac_des3, key, msg, ref)
void
test_main(void)
{
......@@ -96,4 +111,21 @@ test_main(void)
SHEX("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"),
SHEX("e1992190549f6ed5696a2c056c315410"));
/* CMAC-3DES vectors from NIST SP800-38B examples */
test_cmac_des3 (SHEX("0123456789abcdef23456789abcdef01456789abcdef0123"),
SDATA(""),
SHEX("7db0d37df936c550"));
test_cmac_des3 (SHEX("0123456789abcdef23456789abcdef01456789abcdef0123"),
SHEX("6bc1bee22e409f96e93d7e117393172a"),
SHEX("30239cf1f52e6609"));
test_cmac_des3 (SHEX("0123456789abcdef23456789abcdef01456789abcdef0123"),
SHEX("6bc1bee22e409f96e93d7e117393172aae2d8a57"),
SHEX("6c9f3ee4923f6be2"));
test_cmac_des3 (SHEX("0123456789abcdef23456789abcdef01456789abcdef0123"),
SHEX("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51"),
SHEX("99429bd0bf7904e5"));
}