mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 15:28:11 -05:00
Import code from previous AssetBuilder version
This commit is contained in:
84
thirdparty/libtomcrypt/mac/omac/omac_done.c
vendored
Normal file
84
thirdparty/libtomcrypt/mac/omac/omac_done.c
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file omac_done.c
|
||||
OMAC1 support, terminate a stream, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
Terminate an OMAC stream
|
||||
@param omac The OMAC state
|
||||
@param out [out] Destination for the authentication tag
|
||||
@param outlen [in/out] The max size and resulting size of the authentication tag
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
int err, mode;
|
||||
unsigned x;
|
||||
|
||||
LTC_ARGCHK(omac != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((omac->buflen > (int)sizeof(omac->block)) || (omac->buflen < 0) ||
|
||||
(omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* figure out mode */
|
||||
if (omac->buflen != omac->blklen) {
|
||||
/* add the 0x80 byte */
|
||||
omac->block[omac->buflen++] = 0x80;
|
||||
|
||||
/* pad with 0x00 */
|
||||
while (omac->buflen < omac->blklen) {
|
||||
omac->block[omac->buflen++] = 0x00;
|
||||
}
|
||||
mode = 1;
|
||||
} else {
|
||||
mode = 0;
|
||||
}
|
||||
|
||||
/* now xor prev + Lu[mode] */
|
||||
for (x = 0; x < (unsigned)omac->blklen; x++) {
|
||||
omac->block[x] ^= omac->prev[x] ^ omac->Lu[mode][x];
|
||||
}
|
||||
|
||||
/* encrypt it */
|
||||
if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->block, &omac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[omac->cipher_idx].done(&omac->key);
|
||||
|
||||
/* output it */
|
||||
for (x = 0; x < (unsigned)omac->blklen && x < *outlen; x++) {
|
||||
out[x] = omac->block[x];
|
||||
}
|
||||
*outlen = x;
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(omac, sizeof(*omac));
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
97
thirdparty/libtomcrypt/mac/omac/omac_file.c
vendored
Normal file
97
thirdparty/libtomcrypt/mac/omac/omac_file.c
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file omac_file.c
|
||||
OMAC1 support, process a file, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
OMAC a file
|
||||
@param cipher The index of the cipher desired
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param filename The name of the file you wish to OMAC
|
||||
@param out [out] Where the authentication tag is to be stored
|
||||
@param outlen [in/out] The max size and resulting size of the authentication tag
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
|
||||
*/
|
||||
int omac_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
#ifdef LTC_NO_FILE
|
||||
LTC_UNUSED_PARAM(cipher);
|
||||
LTC_UNUSED_PARAM(key);
|
||||
LTC_UNUSED_PARAM(keylen);
|
||||
LTC_UNUSED_PARAM(filename);
|
||||
LTC_UNUSED_PARAM(out);
|
||||
LTC_UNUSED_PARAM(outlen);
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
size_t x;
|
||||
int err;
|
||||
omac_state omac;
|
||||
FILE *in;
|
||||
unsigned char *buf;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(filename != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
in = fopen(filename, "rb");
|
||||
if (in == NULL) {
|
||||
err = CRYPT_FILE_NOTFOUND;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
do {
|
||||
x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
|
||||
if ((err = omac_process(&omac, buf, (unsigned long)x)) != CRYPT_OK) {
|
||||
fclose(in);
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
} while (x == LTC_FILE_READ_BUFSIZE);
|
||||
|
||||
if (fclose(in) != 0) {
|
||||
err = CRYPT_ERROR;
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
|
||||
err = omac_done(&omac, out, outlen);
|
||||
|
||||
LBL_CLEANBUF:
|
||||
zeromem(buf, LTC_FILE_READ_BUFSIZE);
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(&omac, sizeof(omac_state));
|
||||
#endif
|
||||
XFREE(buf);
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
99
thirdparty/libtomcrypt/mac/omac/omac_init.c
vendored
Normal file
99
thirdparty/libtomcrypt/mac/omac/omac_init.c
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file omac_init.c
|
||||
OMAC1 support, initialize state, by Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
Initialize an OMAC state
|
||||
@param omac The OMAC state to initialize
|
||||
@param cipher The index of the desired cipher
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen)
|
||||
{
|
||||
int err, x, y, mask, msb, len;
|
||||
|
||||
LTC_ARGCHK(omac != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
|
||||
/* schedule the key */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* now setup the system */
|
||||
switch (cipher_descriptor[cipher].block_length) {
|
||||
case 8: mask = 0x1B;
|
||||
len = 8;
|
||||
break;
|
||||
case 16: mask = 0x87;
|
||||
len = 16;
|
||||
break;
|
||||
default: return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &omac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ok now we need Lu and Lu^2 [calc one from the other] */
|
||||
|
||||
/* first calc L which is Ek(0) */
|
||||
zeromem(omac->Lu[0], cipher_descriptor[cipher].block_length);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(omac->Lu[0], omac->Lu[0], &omac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* now do the mults, whoopy! */
|
||||
for (x = 0; x < 2; x++) {
|
||||
/* if msb(L * u^(x+1)) = 0 then just shift, otherwise shift and xor constant mask */
|
||||
msb = omac->Lu[x][0] >> 7;
|
||||
|
||||
/* shift left */
|
||||
for (y = 0; y < (len - 1); y++) {
|
||||
omac->Lu[x][y] = ((omac->Lu[x][y] << 1) | (omac->Lu[x][y+1] >> 7)) & 255;
|
||||
}
|
||||
omac->Lu[x][len - 1] = ((omac->Lu[x][len - 1] << 1) ^ (msb ? mask : 0)) & 255;
|
||||
|
||||
/* copy up as require */
|
||||
if (x == 0) {
|
||||
XMEMCPY(omac->Lu[1], omac->Lu[0], sizeof(omac->Lu[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/* setup state */
|
||||
omac->cipher_idx = cipher;
|
||||
omac->buflen = 0;
|
||||
omac->blklen = len;
|
||||
zeromem(omac->prev, sizeof(omac->prev));
|
||||
zeromem(omac->block, sizeof(omac->block));
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
83
thirdparty/libtomcrypt/mac/omac/omac_memory.c
vendored
Normal file
83
thirdparty/libtomcrypt/mac/omac/omac_memory.c
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file omac_memory.c
|
||||
OMAC1 support, process a block of memory, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
OMAC a block of memory
|
||||
@param cipher The index of the desired cipher
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param in The data to send through OMAC
|
||||
@param inlen The length of the data to send through OMAC (octets)
|
||||
@param out [out] The destination of the authentication tag
|
||||
@param outlen [in/out] The max size and resulting size of the authentication tag (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int omac_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
int err;
|
||||
omac_state *omac;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* is the cipher valid? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Use accelerator if found */
|
||||
if (cipher_descriptor[cipher].omac_memory != NULL) {
|
||||
return cipher_descriptor[cipher].omac_memory(key, keylen, in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
/* allocate ram for omac state */
|
||||
omac = XMALLOC(sizeof(omac_state));
|
||||
if (omac == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
/* omac process the message */
|
||||
if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = omac_process(omac, in, inlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
err = CRYPT_OK;
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(omac, sizeof(omac_state));
|
||||
#endif
|
||||
|
||||
XFREE(omac);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
88
thirdparty/libtomcrypt/mac/omac/omac_memory_multi.c
vendored
Normal file
88
thirdparty/libtomcrypt/mac/omac/omac_memory_multi.c
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
@file omac_memory_multi.c
|
||||
OMAC1 support, process multiple blocks of memory, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
OMAC multiple blocks of memory
|
||||
@param cipher The index of the desired cipher
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param out [out] The destination of the authentication tag
|
||||
@param outlen [in/out] The max size and resulting size of the authentication tag (octets)
|
||||
@param in The data to send through OMAC
|
||||
@param inlen The length of the data to send through OMAC (octets)
|
||||
@param ... tuples of (data,len) pairs to OMAC, terminated with a (NULL,x) (x=don't care)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int omac_memory_multi(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...)
|
||||
{
|
||||
int err;
|
||||
omac_state *omac;
|
||||
va_list args;
|
||||
const unsigned char *curptr;
|
||||
unsigned long curlen;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* allocate ram for omac state */
|
||||
omac = XMALLOC(sizeof(omac_state));
|
||||
if (omac == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
/* omac process the message */
|
||||
if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
va_start(args, inlen);
|
||||
curptr = in;
|
||||
curlen = inlen;
|
||||
for (;;) {
|
||||
/* process buf */
|
||||
if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
/* step to next */
|
||||
curptr = va_arg(args, const unsigned char*);
|
||||
if (curptr == NULL) {
|
||||
break;
|
||||
}
|
||||
curlen = va_arg(args, unsigned long);
|
||||
}
|
||||
if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(omac, sizeof(omac_state));
|
||||
#endif
|
||||
XFREE(omac);
|
||||
va_end(args);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
90
thirdparty/libtomcrypt/mac/omac/omac_process.c
vendored
Normal file
90
thirdparty/libtomcrypt/mac/omac/omac_process.c
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file omac_process.c
|
||||
OMAC1 support, process data, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
Process data through OMAC
|
||||
@param omac The OMAC state
|
||||
@param in The input data to send through OMAC
|
||||
@param inlen The length of the input (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen)
|
||||
{
|
||||
unsigned long n, x;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(omac != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((omac->buflen > (int)sizeof(omac->block)) || (omac->buflen < 0) ||
|
||||
(omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
{
|
||||
unsigned long blklen = cipher_descriptor[omac->cipher_idx].block_length;
|
||||
|
||||
if (omac->buflen == 0 && inlen > blklen) {
|
||||
unsigned long y;
|
||||
for (x = 0; x < (inlen - blklen); x += blklen) {
|
||||
for (y = 0; y < blklen; y += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&omac->prev[y])) ^= *(LTC_FAST_TYPE_PTR_CAST(&in[y]));
|
||||
}
|
||||
in += blklen;
|
||||
if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
inlen -= x;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (inlen != 0) {
|
||||
/* ok if the block is full we xor in prev, encrypt and replace prev */
|
||||
if (omac->buflen == omac->blklen) {
|
||||
for (x = 0; x < (unsigned long)omac->blklen; x++) {
|
||||
omac->block[x] ^= omac->prev[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->prev, &omac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
omac->buflen = 0;
|
||||
}
|
||||
|
||||
/* add bytes */
|
||||
n = MIN(inlen, (unsigned long)(omac->blklen - omac->buflen));
|
||||
XMEMCPY(omac->block + omac->buflen, in, n);
|
||||
omac->buflen += n;
|
||||
inlen -= n;
|
||||
in += n;
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
103
thirdparty/libtomcrypt/mac/omac/omac_test.c
vendored
Normal file
103
thirdparty/libtomcrypt/mac/omac/omac_test.c
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file omac_test.c
|
||||
OMAC1 support, self-test, by Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
/**
|
||||
Test the OMAC setup
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled
|
||||
*/
|
||||
int omac_test(void)
|
||||
{
|
||||
#if !defined(LTC_TEST)
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
int keylen, msglen;
|
||||
unsigned char key[16], msg[64], tag[16];
|
||||
} tests[] = {
|
||||
{ 16, 0,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x00 },
|
||||
{ 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
|
||||
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46 }
|
||||
},
|
||||
{ 16, 16,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a },
|
||||
{ 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
|
||||
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c }
|
||||
},
|
||||
{ 16, 40,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 },
|
||||
{ 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
|
||||
0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 }
|
||||
},
|
||||
{ 16, 64,
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
|
||||
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
|
||||
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
|
||||
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
|
||||
{ 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
|
||||
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe }
|
||||
}
|
||||
|
||||
};
|
||||
unsigned char out[16];
|
||||
int x, err, idx;
|
||||
unsigned long len;
|
||||
|
||||
|
||||
/* AES can be under rijndael or aes... try to find it */
|
||||
if ((idx = find_cipher("aes")) == -1) {
|
||||
if ((idx = find_cipher("rijndael")) == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
len = sizeof(out);
|
||||
if ((err = omac_memory(idx, tests[x].key, tests[x].keylen, tests[x].msg, tests[x].msglen, out, &len)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (compare_testvector(out, len, tests[x].tag, sizeof(tests[x].tag), "OMAC", x) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
Reference in New Issue
Block a user