|
Packit Service |
991b93 |
/* siv-cmac-aes256.c
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
AES-SIV, RFC5297
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
Copyright (C) 2017 Nikos Mavrogiannopoulos
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
This file is part of GNU Nettle.
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
GNU Nettle is free software: you can redistribute it and/or
|
|
Packit Service |
991b93 |
modify it under the terms of either:
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
* the GNU Lesser General Public License as published by the Free
|
|
Packit Service |
991b93 |
Software Foundation; either version 3 of the License, or (at your
|
|
Packit Service |
991b93 |
option) any later version.
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
or
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
* the GNU General Public License as published by the Free
|
|
Packit Service |
991b93 |
Software Foundation; either version 2 of the License, or (at your
|
|
Packit Service |
991b93 |
option) any later version.
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
or both in parallel, as here.
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
GNU Nettle is distributed in the hope that it will be useful,
|
|
Packit Service |
991b93 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
991b93 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
991b93 |
General Public License for more details.
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
You should have received copies of the GNU General Public License and
|
|
Packit Service |
991b93 |
the GNU Lesser General Public License along with this program. If
|
|
Packit Service |
991b93 |
not, see http://www.gnu.org/licenses/.
|
|
Packit Service |
991b93 |
*/
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
#if HAVE_CONFIG_H
|
|
Packit Service |
991b93 |
# include "config.h"
|
|
Packit Service |
991b93 |
#endif
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
#include <string.h>
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
#include <nettle/aes.h>
|
|
Packit Service |
991b93 |
#include "siv-cmac.h"
|
|
Packit Service |
991b93 |
#ifdef HAVE_NETTLE_CMAC128_UPDATE
|
|
Packit Service |
991b93 |
#include <nettle/cmac.h>
|
|
Packit Service |
991b93 |
#else
|
|
Packit Service |
991b93 |
#include "cmac.h"
|
|
Packit Service |
991b93 |
#endif
|
|
Packit Service |
991b93 |
#include <nettle/ctr.h>
|
|
Packit Service |
991b93 |
#include <nettle/memxor.h>
|
|
Packit Service |
991b93 |
#include <nettle/memops.h>
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
void
|
|
Packit Service |
991b93 |
siv_cmac_aes256_set_key(struct siv_cmac_aes256_ctx *ctx, const uint8_t *key)
|
|
Packit Service |
991b93 |
{
|
|
Packit Service |
991b93 |
siv_cmac_set_key(&ctx->cmac_key, &ctx->cmac_cipher, &ctx->ctr_cipher, &nettle_aes256, key);
|
|
Packit Service |
991b93 |
}
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
void
|
|
Packit Service |
991b93 |
siv_cmac_aes256_encrypt_message(const struct siv_cmac_aes256_ctx *ctx,
|
|
Packit Service |
991b93 |
size_t nlength, const uint8_t *nonce,
|
|
Packit Service |
991b93 |
size_t alength, const uint8_t *adata,
|
|
Packit Service |
991b93 |
size_t clength, uint8_t *dst, const uint8_t *src)
|
|
Packit Service |
991b93 |
{
|
|
Packit Service |
991b93 |
siv_cmac_encrypt_message(&ctx->cmac_key, &ctx->cmac_cipher,
|
|
Packit Service |
991b93 |
&nettle_aes256, &ctx->ctr_cipher,
|
|
Packit Service |
991b93 |
nlength, nonce, alength, adata,
|
|
Packit Service |
991b93 |
clength, dst, src);
|
|
Packit Service |
991b93 |
}
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
int
|
|
Packit Service |
991b93 |
siv_cmac_aes256_decrypt_message(const struct siv_cmac_aes256_ctx *ctx,
|
|
Packit Service |
991b93 |
size_t nlength, const uint8_t *nonce,
|
|
Packit Service |
991b93 |
size_t alength, const uint8_t *adata,
|
|
Packit Service |
991b93 |
size_t mlength, uint8_t *dst, const uint8_t *src)
|
|
Packit Service |
991b93 |
{
|
|
Packit Service |
991b93 |
return siv_cmac_decrypt_message(&ctx->cmac_key, &ctx->cmac_cipher,
|
|
Packit Service |
991b93 |
&nettle_aes256, &ctx->ctr_cipher,
|
|
Packit Service |
991b93 |
nlength, nonce, alength, adata,
|
|
Packit Service |
991b93 |
mlength, dst, src);
|
|
Packit Service |
991b93 |
}
|