diff --git a/ChangeLog b/ChangeLog index 41cfe335782d7f7bc84178fcd1357ccb660be6d7..7be5b10dd682d75de4e3f1e8123a56c61a9eebf0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-04-30 Niels Möller <nisse@lysator.liu.se> + + Based on a patch contributed by Nikos Mavrogiannopoulos. + * cmac.c (_cmac128_block_mulx): Renamed function... + (block_mulx): ... from old name. + * cmac-internal.h (_cmac128_block_mulx): New file, declare function. + * Makefile.in (DISTFILES): Added cmac-internal.h. + 2019-04-27 Niels Möller <nisse@lysator.liu.se> From Simo Sorce: diff --git a/Makefile.in b/Makefile.in index 440de9f7bb59211d3fea3da59296ad677cd106eb..fefc7887cce4b9fff2e71bfbebe205ce71b50d53 100644 --- a/Makefile.in +++ b/Makefile.in @@ -229,7 +229,7 @@ DISTFILES = $(SOURCES) $(HEADERS) getopt.h getopt_int.h \ INSTALL NEWS ChangeLog \ nettle.pc.in hogweed.pc.in \ $(des_headers) descore.README desdata.stamp \ - aes-internal.h camellia-internal.h serpent-internal.h \ + aes-internal.h camellia-internal.h cmac-internal.h serpent-internal.h \ cast128_sboxes.h desinfo.h desCode.h \ ripemd160-internal.h sha2-internal.h \ memxor-internal.h nettle-internal.h nettle-write.h \ diff --git a/cmac-internal.h b/cmac-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..80db7fcc58cd494474fb0c0a43c5b8110813d00a --- /dev/null +++ b/cmac-internal.h @@ -0,0 +1,54 @@ +/* cmac-internal.h + + CMAC mode internal functions + + Copyright (C) 2017 Red Hat, Inc. + + Contributed by Nikos Mavrogiannopoulos + + 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/. +*/ + +#ifndef NETTLE_CMAC_INTERNAL_H_INCLUDED +#define NETTLE_CMAC_INTERNAL_H_INCLUDED + +#include "cmac.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define _cmac128_block_mulx _nettle_cmac128_block_mulx + +void _cmac128_block_mulx(union nettle_block16 *out, + const union nettle_block16 *in); + +#ifdef __cplusplus +} +#endif + +#endif /* CMAC_INTERNAL_H_INCLUDED */ diff --git a/cmac.c b/cmac.c index ed3b5eb8f613c7115f11ffada7f88c3608c79cf4..2f15a74d81e6c0d3a402821a6596324dc1868c5b 100644 --- a/cmac.c +++ b/cmac.c @@ -44,13 +44,14 @@ #include "memxor.h" #include "nettle-internal.h" +#include "cmac-internal.h" #include "macros.h" /* shift one and XOR with 0x87. */ #if WORDS_BIGENDIAN -static void -block_mulx(union nettle_block16 *dst, - const union nettle_block16 *src) +void +_cmac128_block_mulx(union nettle_block16 *dst, + const union nettle_block16 *src) { uint64_t carry = src->u64[0] >> 63; dst->u64[0] = (src->u64[0] << 1) | (src->u64[1] >> 63); @@ -59,9 +60,9 @@ block_mulx(union nettle_block16 *dst, #else /* !WORDS_BIGENDIAN */ #define LE_SHIFT(x) ((((x) & 0x7f7f7f7f7f7f7f7f) << 1) | \ (((x) & 0x8080808080808080) >> 15)) -static void -block_mulx(union nettle_block16 *dst, - const union nettle_block16 *src) +void +_cmac128_block_mulx(union nettle_block16 *dst, + const union nettle_block16 *src) { uint64_t carry = (src->u64[0] & 0x80) >> 7; dst->u64[0] = LE_SHIFT(src->u64[0]) | ((src->u64[1] & 0x80) << 49); @@ -83,8 +84,8 @@ cmac128_set_key(struct cmac128_ctx *ctx, const void *cipher, /* step 1 - generate subkeys k1 and k2 */ encrypt(cipher, 16, L->b, const_zero); - block_mulx(&ctx->K1, L); - block_mulx(&ctx->K2, &ctx->K1); + _cmac128_block_mulx(&ctx->K1, L); + _cmac128_block_mulx(&ctx->K2, &ctx->K1); } #define MIN(x,y) ((x)<(y)?(x):(y))