mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Import code from previous AssetBuilder version
This commit is contained in:
131
thirdparty/libtomcrypt/misc/adler32.c
vendored
Normal file
131
thirdparty/libtomcrypt/misc/adler32.c
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
/* 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 adler32.c
|
||||
Adler-32 checksum algorithm
|
||||
Written and placed in the public domain by Wei Dai
|
||||
Adapted for libtomcrypt by Steffen Jaeckel
|
||||
*/
|
||||
#ifdef LTC_ADLER32
|
||||
|
||||
static const unsigned long _adler32_base = 65521;
|
||||
|
||||
void adler32_init(adler32_state *ctx)
|
||||
{
|
||||
LTC_ARGCHKVD(ctx != NULL);
|
||||
ctx->s[0] = 1;
|
||||
ctx->s[1] = 0;
|
||||
}
|
||||
|
||||
void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned long length)
|
||||
{
|
||||
unsigned long s1, s2;
|
||||
|
||||
LTC_ARGCHKVD(ctx != NULL);
|
||||
LTC_ARGCHKVD(input != NULL);
|
||||
s1 = ctx->s[0];
|
||||
s2 = ctx->s[1];
|
||||
|
||||
if (length % 8 != 0) {
|
||||
do {
|
||||
s1 += *input++;
|
||||
s2 += s1;
|
||||
length--;
|
||||
} while (length % 8 != 0);
|
||||
|
||||
if (s1 >= _adler32_base)
|
||||
s1 -= _adler32_base;
|
||||
s2 %= _adler32_base;
|
||||
}
|
||||
|
||||
while (length > 0) {
|
||||
s1 += input[0];
|
||||
s2 += s1;
|
||||
s1 += input[1];
|
||||
s2 += s1;
|
||||
s1 += input[2];
|
||||
s2 += s1;
|
||||
s1 += input[3];
|
||||
s2 += s1;
|
||||
s1 += input[4];
|
||||
s2 += s1;
|
||||
s1 += input[5];
|
||||
s2 += s1;
|
||||
s1 += input[6];
|
||||
s2 += s1;
|
||||
s1 += input[7];
|
||||
s2 += s1;
|
||||
|
||||
length -= 8;
|
||||
input += 8;
|
||||
|
||||
if (s1 >= _adler32_base)
|
||||
s1 -= _adler32_base;
|
||||
s2 %= _adler32_base;
|
||||
}
|
||||
|
||||
LTC_ARGCHKVD(s1 < _adler32_base);
|
||||
LTC_ARGCHKVD(s2 < _adler32_base);
|
||||
|
||||
ctx->s[0] = (unsigned short)s1;
|
||||
ctx->s[1] = (unsigned short)s2;
|
||||
}
|
||||
|
||||
void adler32_finish(adler32_state *ctx, void *hash, unsigned long size)
|
||||
{
|
||||
unsigned char* h;
|
||||
|
||||
LTC_ARGCHKVD(ctx != NULL);
|
||||
LTC_ARGCHKVD(hash != NULL);
|
||||
|
||||
h = hash;
|
||||
|
||||
switch (size) {
|
||||
default:
|
||||
h[3] = ctx->s[0] & 0x0ff;
|
||||
/* FALLTHROUGH */
|
||||
case 3:
|
||||
h[2] = (ctx->s[0] >> 8) & 0x0ff;
|
||||
/* FALLTHROUGH */
|
||||
case 2:
|
||||
h[1] = ctx->s[1] & 0x0ff;
|
||||
/* FALLTHROUGH */
|
||||
case 1:
|
||||
h[0] = (ctx->s[1] >> 8) & 0x0ff;
|
||||
/* FALLTHROUGH */
|
||||
case 0:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
int adler32_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
const void* in = "libtomcrypt";
|
||||
const unsigned char adler32[] = { 0x1b, 0xe8, 0x04, 0xba };
|
||||
unsigned char out[4];
|
||||
adler32_state ctx;
|
||||
adler32_init(&ctx);
|
||||
adler32_update(&ctx, in, strlen(in));
|
||||
adler32_finish(&ctx, out, 4);
|
||||
if (compare_testvector(adler32, 4, out, 4, "adler32", 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 */
|
196
thirdparty/libtomcrypt/misc/base64/base64_decode.c
vendored
Normal file
196
thirdparty/libtomcrypt/misc/base64/base64_decode.c
vendored
Normal file
@ -0,0 +1,196 @@
|
||||
/* 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 base64_decode.c
|
||||
Compliant base64 code donated by Wayne Scott (wscott@bitmover.com)
|
||||
base64 URL Safe variant (RFC 4648 section 5) by Karel Miko
|
||||
*/
|
||||
|
||||
|
||||
#if defined(LTC_BASE64) || defined (LTC_BASE64_URL)
|
||||
|
||||
#if defined(LTC_BASE64)
|
||||
static const unsigned char map_base64[256] = {
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
|
||||
255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
|
||||
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
|
||||
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255 };
|
||||
#endif /* LTC_BASE64 */
|
||||
|
||||
static const unsigned char map_base64url[] = {
|
||||
#if defined(LTC_BASE64_URL)
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
|
||||
255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 63,
|
||||
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
|
||||
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255
|
||||
#endif /* LTC_BASE64_URL */
|
||||
};
|
||||
|
||||
enum {
|
||||
relaxed = 0,
|
||||
strict = 1
|
||||
};
|
||||
|
||||
static int _base64_decode_internal(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *map, int is_strict)
|
||||
{
|
||||
unsigned long t, x, y, z;
|
||||
unsigned char c;
|
||||
int g;
|
||||
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
g = 0; /* '=' counter */
|
||||
for (x = y = z = t = 0; x < inlen; x++) {
|
||||
c = map[in[x]&0xFF];
|
||||
if (c == 254) {
|
||||
g++;
|
||||
continue;
|
||||
}
|
||||
else if (is_strict && g > 0) {
|
||||
/* we only allow '=' to be at the end */
|
||||
return CRYPT_INVALID_PACKET;
|
||||
}
|
||||
if (c == 255) {
|
||||
if (is_strict)
|
||||
return CRYPT_INVALID_PACKET;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
t = (t<<6)|c;
|
||||
|
||||
if (++y == 4) {
|
||||
if (z + 3 > *outlen) return CRYPT_BUFFER_OVERFLOW;
|
||||
out[z++] = (unsigned char)((t>>16)&255);
|
||||
out[z++] = (unsigned char)((t>>8)&255);
|
||||
out[z++] = (unsigned char)(t&255);
|
||||
y = t = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (y != 0) {
|
||||
if (y == 1) return CRYPT_INVALID_PACKET;
|
||||
if ((y + g) != 4 && is_strict && map != map_base64url) return CRYPT_INVALID_PACKET;
|
||||
t = t << (6 * (4 - y));
|
||||
if (z + y - 1 > *outlen) return CRYPT_BUFFER_OVERFLOW;
|
||||
if (y >= 2) out[z++] = (unsigned char) ((t >> 16) & 255);
|
||||
if (y == 3) out[z++] = (unsigned char) ((t >> 8) & 255);
|
||||
}
|
||||
*outlen = z;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#if defined(LTC_BASE64)
|
||||
/**
|
||||
Relaxed base64 decode a block of memory
|
||||
@param in The base64 data to decode
|
||||
@param inlen The length of the base64 data
|
||||
@param out [out] The destination of the binary decoded data
|
||||
@param outlen [in/out] The max size and resulting size of the decoded data
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int base64_decode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_decode_internal(in, inlen, out, outlen, map_base64, relaxed);
|
||||
}
|
||||
|
||||
/**
|
||||
Strict base64 decode a block of memory
|
||||
@param in The base64 data to decode
|
||||
@param inlen The length of the base64 data
|
||||
@param out [out] The destination of the binary decoded data
|
||||
@param outlen [in/out] The max size and resulting size of the decoded data
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int base64_strict_decode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_decode_internal(in, inlen, out, outlen, map_base64, strict);
|
||||
}
|
||||
#endif /* LTC_BASE64 */
|
||||
|
||||
#if defined(LTC_BASE64_URL)
|
||||
/**
|
||||
Relaxed base64 (URL Safe, RFC 4648 section 5) decode a block of memory
|
||||
@param in The base64 data to decode
|
||||
@param inlen The length of the base64 data
|
||||
@param out [out] The destination of the binary decoded data
|
||||
@param outlen [in/out] The max size and resulting size of the decoded data
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int base64url_decode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_decode_internal(in, inlen, out, outlen, map_base64url, relaxed);
|
||||
}
|
||||
|
||||
/**
|
||||
Strict base64 (URL Safe, RFC 4648 section 5) decode a block of memory
|
||||
@param in The base64 data to decode
|
||||
@param inlen The length of the base64 data
|
||||
@param out [out] The destination of the binary decoded data
|
||||
@param outlen [in/out] The max size and resulting size of the decoded data
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int base64url_strict_decode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_decode_internal(in, inlen, out, outlen, map_base64url, strict);
|
||||
}
|
||||
#endif /* LTC_BASE64_URL */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
124
thirdparty/libtomcrypt/misc/base64/base64_encode.c
vendored
Normal file
124
thirdparty/libtomcrypt/misc/base64/base64_encode.c
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
/* 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 base64_encode.c
|
||||
Compliant base64 encoder donated by Wayne Scott (wscott@bitmover.com)
|
||||
base64 URL Safe variant (RFC 4648 section 5) by Karel Miko
|
||||
*/
|
||||
|
||||
|
||||
#if defined(LTC_BASE64) || defined (LTC_BASE64_URL)
|
||||
|
||||
#if defined(LTC_BASE64)
|
||||
static const char * const codes_base64 =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
#endif /* LTC_BASE64 */
|
||||
|
||||
#if defined(LTC_BASE64_URL)
|
||||
static const char * const codes_base64url =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
#endif /* LTC_BASE64_URL */
|
||||
|
||||
static int _base64_encode_internal(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const char *codes, int pad)
|
||||
{
|
||||
unsigned long i, len2, leven;
|
||||
unsigned char *p;
|
||||
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* valid output size ? */
|
||||
len2 = 4 * ((inlen + 2) / 3);
|
||||
if (*outlen < len2 + 1) {
|
||||
*outlen = len2 + 1;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
p = out;
|
||||
leven = 3*(inlen / 3);
|
||||
for (i = 0; i < leven; i += 3) {
|
||||
*p++ = codes[(in[0] >> 2) & 0x3F];
|
||||
*p++ = codes[(((in[0] & 3) << 4) + (in[1] >> 4)) & 0x3F];
|
||||
*p++ = codes[(((in[1] & 0xf) << 2) + (in[2] >> 6)) & 0x3F];
|
||||
*p++ = codes[in[2] & 0x3F];
|
||||
in += 3;
|
||||
}
|
||||
/* Pad it if necessary... */
|
||||
if (i < inlen) {
|
||||
unsigned a = in[0];
|
||||
unsigned b = (i+1 < inlen) ? in[1] : 0;
|
||||
|
||||
*p++ = codes[(a >> 2) & 0x3F];
|
||||
*p++ = codes[(((a & 3) << 4) + (b >> 4)) & 0x3F];
|
||||
if (pad) {
|
||||
*p++ = (i+1 < inlen) ? codes[(((b & 0xf) << 2)) & 0x3F] : '=';
|
||||
*p++ = '=';
|
||||
}
|
||||
else {
|
||||
if (i+1 < inlen) *p++ = codes[(((b & 0xf) << 2)) & 0x3F];
|
||||
}
|
||||
}
|
||||
|
||||
/* append a NULL byte */
|
||||
*p = '\0';
|
||||
|
||||
/* return ok */
|
||||
*outlen = (unsigned long)(p - out);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#if defined(LTC_BASE64)
|
||||
/**
|
||||
base64 Encode a buffer (NUL terminated)
|
||||
@param in The input buffer to encode
|
||||
@param inlen The length of the input buffer
|
||||
@param out [out] The destination of the base64 encoded data
|
||||
@param outlen [in/out] The max size and resulting size
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int base64_encode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_encode_internal(in, inlen, out, outlen, codes_base64, 1);
|
||||
}
|
||||
#endif /* LTC_BASE64 */
|
||||
|
||||
|
||||
#if defined(LTC_BASE64_URL)
|
||||
/**
|
||||
base64 (URL Safe, RFC 4648 section 5) Encode a buffer (NUL terminated)
|
||||
@param in The input buffer to encode
|
||||
@param inlen The length of the input buffer
|
||||
@param out [out] The destination of the base64 encoded data
|
||||
@param outlen [in/out] The max size and resulting size
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int base64url_encode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_encode_internal(in, inlen, out, outlen, codes_base64url, 0);
|
||||
}
|
||||
|
||||
int base64url_strict_encode(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _base64_encode_internal(in, inlen, out, outlen, codes_base64url, 1);
|
||||
}
|
||||
#endif /* LTC_BASE64_URL */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
32
thirdparty/libtomcrypt/misc/burn_stack.c
vendored
Normal file
32
thirdparty/libtomcrypt/misc/burn_stack.c
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/* 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 burn_stack.c
|
||||
Burn stack, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Burn some stack memory
|
||||
@param len amount of stack to burn in bytes
|
||||
*/
|
||||
void burn_stack(unsigned long len)
|
||||
{
|
||||
unsigned char buf[32];
|
||||
zeromem(buf, sizeof(buf));
|
||||
if (len > (unsigned long)sizeof(buf))
|
||||
burn_stack(len - sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
87
thirdparty/libtomcrypt/misc/compare_testvector.c
vendored
Normal file
87
thirdparty/libtomcrypt/misc/compare_testvector.c
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
/* 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 compare_testvector.c
|
||||
Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
|
||||
static void _print_hex(const char* what, const void* v, const unsigned long l)
|
||||
{
|
||||
const unsigned char* p = v;
|
||||
unsigned long x, y = 0, z;
|
||||
fprintf(stderr, "%s contents: \n", what);
|
||||
for (x = 0; x < l; ) {
|
||||
fprintf(stderr, "%02X ", p[x]);
|
||||
if (!(++x % 16) || x == l) {
|
||||
if((x % 16) != 0) {
|
||||
z = 16 - (x % 16);
|
||||
if(z >= 8)
|
||||
fprintf(stderr, " ");
|
||||
for (; z != 0; --z) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
}
|
||||
fprintf(stderr, " | ");
|
||||
for(; y < x; y++) {
|
||||
if((y % 8) == 0)
|
||||
fprintf(stderr, " ");
|
||||
if(isgraph(p[y]))
|
||||
fprintf(stderr, "%c", p[y]);
|
||||
else
|
||||
fprintf(stderr, ".");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
else if((x % 8) == 0) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
Compare two test-vectors
|
||||
|
||||
@param is The data as it is
|
||||
@param is_len The length of is
|
||||
@param should The data as it should
|
||||
@param should_len The length of should
|
||||
@param what The type of the data
|
||||
@param which The iteration count
|
||||
@return 0 on equality, -1 or 1 on difference
|
||||
*/
|
||||
int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
|
||||
{
|
||||
int res = 0;
|
||||
if(is_len != should_len)
|
||||
res = is_len > should_len ? -1 : 1;
|
||||
else
|
||||
res = XMEMCMP(is, should, is_len);
|
||||
|
||||
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
|
||||
if (res != 0) {
|
||||
fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
|
||||
_print_hex("SHOULD", should, should_len);
|
||||
_print_hex("IS ", is, is_len);
|
||||
}
|
||||
#else
|
||||
LTC_UNUSED_PARAM(which);
|
||||
LTC_UNUSED_PARAM(what);
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
202
thirdparty/libtomcrypt/misc/crc32.c
vendored
Normal file
202
thirdparty/libtomcrypt/misc/crc32.c
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
/* 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 crc32.c
|
||||
CRC-32 checksum algorithm
|
||||
Written and placed in the public domain by Wei Dai
|
||||
Adapted for libtomcrypt by Steffen Jaeckel
|
||||
*/
|
||||
#ifdef LTC_CRC32
|
||||
|
||||
static const ulong32 _CRC32_NEGL = 0xffffffffUL;
|
||||
|
||||
#if defined(ENDIAN_LITTLE)
|
||||
#define CRC32_INDEX(c) (c & 0xff)
|
||||
#define CRC32_SHIFTED(c) (c >> 8)
|
||||
#elif defined(ENDIAN_BIG)
|
||||
#define CRC32_INDEX(c) (c >> 24)
|
||||
#define CRC32_SHIFTED(c) (c << 8)
|
||||
#else
|
||||
#error The existing CRC32 implementation only works properly when the endianness of the target platform is known.
|
||||
#endif
|
||||
|
||||
/* Table of CRC-32's of all single byte values (made by makecrc.c) */
|
||||
static const ulong32 crc32_m_tab[] =
|
||||
{
|
||||
#if defined(ENDIAN_LITTLE)
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
|
||||
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
|
||||
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
|
||||
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
|
||||
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
|
||||
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
|
||||
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
|
||||
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
|
||||
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
|
||||
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
|
||||
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
|
||||
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
|
||||
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
|
||||
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
|
||||
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
|
||||
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
|
||||
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
|
||||
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
|
||||
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
|
||||
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
|
||||
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
|
||||
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
|
||||
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
|
||||
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
|
||||
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
|
||||
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
|
||||
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
|
||||
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
|
||||
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
|
||||
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
|
||||
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
|
||||
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
|
||||
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
|
||||
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
|
||||
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
|
||||
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
|
||||
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
|
||||
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
|
||||
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
|
||||
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
|
||||
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
|
||||
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
|
||||
0x2d02ef8dL
|
||||
#else
|
||||
0x00000000L, 0x96300777L, 0x2c610eeeL, 0xba510999L, 0x19c46d07L,
|
||||
0x8ff46a70L, 0x35a563e9L, 0xa395649eL, 0x3288db0eL, 0xa4b8dc79L,
|
||||
0x1ee9d5e0L, 0x88d9d297L, 0x2b4cb609L, 0xbd7cb17eL, 0x072db8e7L,
|
||||
0x911dbf90L, 0x6410b71dL, 0xf220b06aL, 0x4871b9f3L, 0xde41be84L,
|
||||
0x7dd4da1aL, 0xebe4dd6dL, 0x51b5d4f4L, 0xc785d383L, 0x56986c13L,
|
||||
0xc0a86b64L, 0x7af962fdL, 0xecc9658aL, 0x4f5c0114L, 0xd96c0663L,
|
||||
0x633d0ffaL, 0xf50d088dL, 0xc8206e3bL, 0x5e10694cL, 0xe44160d5L,
|
||||
0x727167a2L, 0xd1e4033cL, 0x47d4044bL, 0xfd850dd2L, 0x6bb50aa5L,
|
||||
0xfaa8b535L, 0x6c98b242L, 0xd6c9bbdbL, 0x40f9bcacL, 0xe36cd832L,
|
||||
0x755cdf45L, 0xcf0dd6dcL, 0x593dd1abL, 0xac30d926L, 0x3a00de51L,
|
||||
0x8051d7c8L, 0x1661d0bfL, 0xb5f4b421L, 0x23c4b356L, 0x9995bacfL,
|
||||
0x0fa5bdb8L, 0x9eb80228L, 0x0888055fL, 0xb2d90cc6L, 0x24e90bb1L,
|
||||
0x877c6f2fL, 0x114c6858L, 0xab1d61c1L, 0x3d2d66b6L, 0x9041dc76L,
|
||||
0x0671db01L, 0xbc20d298L, 0x2a10d5efL, 0x8985b171L, 0x1fb5b606L,
|
||||
0xa5e4bf9fL, 0x33d4b8e8L, 0xa2c90778L, 0x34f9000fL, 0x8ea80996L,
|
||||
0x18980ee1L, 0xbb0d6a7fL, 0x2d3d6d08L, 0x976c6491L, 0x015c63e6L,
|
||||
0xf4516b6bL, 0x62616c1cL, 0xd8306585L, 0x4e0062f2L, 0xed95066cL,
|
||||
0x7ba5011bL, 0xc1f40882L, 0x57c40ff5L, 0xc6d9b065L, 0x50e9b712L,
|
||||
0xeab8be8bL, 0x7c88b9fcL, 0xdf1ddd62L, 0x492dda15L, 0xf37cd38cL,
|
||||
0x654cd4fbL, 0x5861b24dL, 0xce51b53aL, 0x7400bca3L, 0xe230bbd4L,
|
||||
0x41a5df4aL, 0xd795d83dL, 0x6dc4d1a4L, 0xfbf4d6d3L, 0x6ae96943L,
|
||||
0xfcd96e34L, 0x468867adL, 0xd0b860daL, 0x732d0444L, 0xe51d0333L,
|
||||
0x5f4c0aaaL, 0xc97c0dddL, 0x3c710550L, 0xaa410227L, 0x10100bbeL,
|
||||
0x86200cc9L, 0x25b56857L, 0xb3856f20L, 0x09d466b9L, 0x9fe461ceL,
|
||||
0x0ef9de5eL, 0x98c9d929L, 0x2298d0b0L, 0xb4a8d7c7L, 0x173db359L,
|
||||
0x810db42eL, 0x3b5cbdb7L, 0xad6cbac0L, 0x2083b8edL, 0xb6b3bf9aL,
|
||||
0x0ce2b603L, 0x9ad2b174L, 0x3947d5eaL, 0xaf77d29dL, 0x1526db04L,
|
||||
0x8316dc73L, 0x120b63e3L, 0x843b6494L, 0x3e6a6d0dL, 0xa85a6a7aL,
|
||||
0x0bcf0ee4L, 0x9dff0993L, 0x27ae000aL, 0xb19e077dL, 0x44930ff0L,
|
||||
0xd2a30887L, 0x68f2011eL, 0xfec20669L, 0x5d5762f7L, 0xcb676580L,
|
||||
0x71366c19L, 0xe7066b6eL, 0x761bd4feL, 0xe02bd389L, 0x5a7ada10L,
|
||||
0xcc4add67L, 0x6fdfb9f9L, 0xf9efbe8eL, 0x43beb717L, 0xd58eb060L,
|
||||
0xe8a3d6d6L, 0x7e93d1a1L, 0xc4c2d838L, 0x52f2df4fL, 0xf167bbd1L,
|
||||
0x6757bca6L, 0xdd06b53fL, 0x4b36b248L, 0xda2b0dd8L, 0x4c1b0aafL,
|
||||
0xf64a0336L, 0x607a0441L, 0xc3ef60dfL, 0x55df67a8L, 0xef8e6e31L,
|
||||
0x79be6946L, 0x8cb361cbL, 0x1a8366bcL, 0xa0d26f25L, 0x36e26852L,
|
||||
0x95770cccL, 0x03470bbbL, 0xb9160222L, 0x2f260555L, 0xbe3bbac5L,
|
||||
0x280bbdb2L, 0x925ab42bL, 0x046ab35cL, 0xa7ffd7c2L, 0x31cfd0b5L,
|
||||
0x8b9ed92cL, 0x1daede5bL, 0xb0c2649bL, 0x26f263ecL, 0x9ca36a75L,
|
||||
0x0a936d02L, 0xa906099cL, 0x3f360eebL, 0x85670772L, 0x13570005L,
|
||||
0x824abf95L, 0x147ab8e2L, 0xae2bb17bL, 0x381bb60cL, 0x9b8ed292L,
|
||||
0x0dbed5e5L, 0xb7efdc7cL, 0x21dfdb0bL, 0xd4d2d386L, 0x42e2d4f1L,
|
||||
0xf8b3dd68L, 0x6e83da1fL, 0xcd16be81L, 0x5b26b9f6L, 0xe177b06fL,
|
||||
0x7747b718L, 0xe65a0888L, 0x706a0fffL, 0xca3b0666L, 0x5c0b0111L,
|
||||
0xff9e658fL, 0x69ae62f8L, 0xd3ff6b61L, 0x45cf6c16L, 0x78e20aa0L,
|
||||
0xeed20dd7L, 0x5483044eL, 0xc2b30339L, 0x612667a7L, 0xf71660d0L,
|
||||
0x4d476949L, 0xdb776e3eL, 0x4a6ad1aeL, 0xdc5ad6d9L, 0x660bdf40L,
|
||||
0xf03bd837L, 0x53aebca9L, 0xc59ebbdeL, 0x7fcfb247L, 0xe9ffb530L,
|
||||
0x1cf2bdbdL, 0x8ac2bacaL, 0x3093b353L, 0xa6a3b424L, 0x0536d0baL,
|
||||
0x9306d7cdL, 0x2957de54L, 0xbf67d923L, 0x2e7a66b3L, 0xb84a61c4L,
|
||||
0x021b685dL, 0x942b6f2aL, 0x37be0bb4L, 0xa18e0cc3L, 0x1bdf055aL,
|
||||
0x8def022dL
|
||||
#endif
|
||||
};
|
||||
|
||||
void crc32_init(crc32_state *ctx)
|
||||
{
|
||||
LTC_ARGCHKVD(ctx != NULL);
|
||||
ctx->crc = _CRC32_NEGL;
|
||||
}
|
||||
|
||||
void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long length)
|
||||
{
|
||||
ulong32 crc;
|
||||
LTC_ARGCHKVD(ctx != NULL);
|
||||
LTC_ARGCHKVD(input != NULL);
|
||||
crc = ctx->crc;
|
||||
|
||||
while (length--)
|
||||
crc = crc32_m_tab[CRC32_INDEX(crc) ^ *input++] ^ CRC32_SHIFTED(crc);
|
||||
|
||||
ctx->crc = crc;
|
||||
}
|
||||
|
||||
void crc32_finish(crc32_state *ctx, void *hash, unsigned long size)
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned char* h;
|
||||
ulong32 crc;
|
||||
LTC_ARGCHKVD(ctx != NULL);
|
||||
LTC_ARGCHKVD(hash != NULL);
|
||||
|
||||
h = hash;
|
||||
crc = ctx->crc;
|
||||
crc ^= _CRC32_NEGL;
|
||||
|
||||
if (size > 4) size = 4;
|
||||
for (i = 0; i < size; i++) {
|
||||
h[i] = ((unsigned char*)&(crc))[size-i-1];
|
||||
}
|
||||
}
|
||||
|
||||
int crc32_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
const void* in = "libtomcrypt";
|
||||
const unsigned char crc32[] = { 0xb3, 0x73, 0x76, 0xef };
|
||||
unsigned char out[4];
|
||||
crc32_state ctx;
|
||||
crc32_init(&ctx);
|
||||
crc32_update(&ctx, in, strlen(in));
|
||||
crc32_finish(&ctx, out, 4);
|
||||
if (compare_testvector(crc32, 4, out, 4, "CRC32", 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 */
|
496
thirdparty/libtomcrypt/misc/crypt/crypt.c
vendored
Normal file
496
thirdparty/libtomcrypt/misc/crypt/crypt.c
vendored
Normal file
@ -0,0 +1,496 @@
|
||||
/* 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 crypt.c
|
||||
Build strings, Tom St Denis
|
||||
*/
|
||||
#define NAME_VALUE(s) #s"="NAME(s)
|
||||
#define NAME(s) #s
|
||||
|
||||
const char *crypt_build_settings =
|
||||
"LibTomCrypt " SCRYPT " (www.libtom.net)\n"
|
||||
"LibTomCrypt is public domain software.\n"
|
||||
#if defined(INCLUDE_BUILD_DATE)
|
||||
"Built on " __DATE__ " at " __TIME__ "\n"
|
||||
#endif
|
||||
"\n\nEndianness: "
|
||||
#if defined(ENDIAN_NEUTRAL)
|
||||
"neutral/"
|
||||
#endif
|
||||
#if defined(ENDIAN_LITTLE)
|
||||
"little"
|
||||
#elif defined(ENDIAN_BIG)
|
||||
"big"
|
||||
#endif
|
||||
#if defined(ENDIAN_32BITWORD)
|
||||
" (32-bit words)\n"
|
||||
#elif defined(ENDIAN_64BITWORD)
|
||||
" (64-bit words)\n"
|
||||
#else
|
||||
" (no wordsize defined)\n"
|
||||
#endif
|
||||
"Clean stack: "
|
||||
#if defined(LTC_CLEAN_STACK)
|
||||
"enabled\n"
|
||||
#else
|
||||
"disabled\n"
|
||||
#endif
|
||||
"\nCiphers built-in:\n"
|
||||
#if defined(LTC_BLOWFISH)
|
||||
" Blowfish\n"
|
||||
#endif
|
||||
#if defined(LTC_RC2)
|
||||
" RC2\n"
|
||||
#endif
|
||||
#if defined(LTC_RC5)
|
||||
" RC5\n"
|
||||
#endif
|
||||
#if defined(LTC_RC6)
|
||||
" RC6\n"
|
||||
#endif
|
||||
#if defined(LTC_SAFERP)
|
||||
" Safer+\n"
|
||||
#endif
|
||||
#if defined(LTC_SAFER)
|
||||
" Safer\n"
|
||||
#endif
|
||||
#if defined(LTC_RIJNDAEL)
|
||||
" Rijndael\n"
|
||||
#endif
|
||||
#if defined(LTC_XTEA)
|
||||
" XTEA\n"
|
||||
#endif
|
||||
#if defined(LTC_TWOFISH)
|
||||
" Twofish "
|
||||
#if defined(LTC_TWOFISH_SMALL) && defined(LTC_TWOFISH_TABLES) && defined(LTC_TWOFISH_ALL_TABLES)
|
||||
"(small, tables, all_tables)\n"
|
||||
#elif defined(LTC_TWOFISH_SMALL) && defined(LTC_TWOFISH_TABLES)
|
||||
"(small, tables)\n"
|
||||
#elif defined(LTC_TWOFISH_SMALL) && defined(LTC_TWOFISH_ALL_TABLES)
|
||||
"(small, all_tables)\n"
|
||||
#elif defined(LTC_TWOFISH_TABLES) && defined(LTC_TWOFISH_ALL_TABLES)
|
||||
"(tables, all_tables)\n"
|
||||
#elif defined(LTC_TWOFISH_SMALL)
|
||||
"(small)\n"
|
||||
#elif defined(LTC_TWOFISH_TABLES)
|
||||
"(tables)\n"
|
||||
#elif defined(LTC_TWOFISH_ALL_TABLES)
|
||||
"(all_tables)\n"
|
||||
#else
|
||||
"\n"
|
||||
#endif
|
||||
#endif
|
||||
#if defined(LTC_DES)
|
||||
" DES\n"
|
||||
#endif
|
||||
#if defined(LTC_CAST5)
|
||||
" CAST5\n"
|
||||
#endif
|
||||
#if defined(LTC_NOEKEON)
|
||||
" Noekeon\n"
|
||||
#endif
|
||||
#if defined(LTC_SKIPJACK)
|
||||
" Skipjack\n"
|
||||
#endif
|
||||
#if defined(LTC_KHAZAD)
|
||||
" Khazad\n"
|
||||
#endif
|
||||
#if defined(LTC_ANUBIS)
|
||||
" Anubis "
|
||||
#endif
|
||||
#if defined(LTC_ANUBIS_TWEAK)
|
||||
" (tweaked)"
|
||||
#endif
|
||||
"\n"
|
||||
#if defined(LTC_KSEED)
|
||||
" KSEED\n"
|
||||
#endif
|
||||
#if defined(LTC_KASUMI)
|
||||
" KASUMI\n"
|
||||
#endif
|
||||
#if defined(LTC_MULTI2)
|
||||
" MULTI2\n"
|
||||
#endif
|
||||
#if defined(LTC_CAMELLIA)
|
||||
" Camellia\n"
|
||||
#endif
|
||||
"Stream ciphers built-in:\n"
|
||||
#if defined(LTC_CHACHA)
|
||||
" ChaCha\n"
|
||||
#endif
|
||||
#if defined(LTC_RC4_STREAM)
|
||||
" RC4\n"
|
||||
#endif
|
||||
#if defined(LTC_SOBER128_STREAM)
|
||||
" SOBER128\n"
|
||||
#endif
|
||||
|
||||
"\nHashes built-in:\n"
|
||||
#if defined(LTC_SHA3)
|
||||
" SHA3\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA512)
|
||||
" SHA-512\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA384)
|
||||
" SHA-384\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA512_256)
|
||||
" SHA-512/256\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA256)
|
||||
" SHA-256\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA512_224)
|
||||
" SHA-512/224\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA224)
|
||||
" SHA-224\n"
|
||||
#endif
|
||||
#if defined(LTC_TIGER)
|
||||
" TIGER\n"
|
||||
#endif
|
||||
#if defined(LTC_SHA1)
|
||||
" SHA1\n"
|
||||
#endif
|
||||
#if defined(LTC_MD5)
|
||||
" MD5\n"
|
||||
#endif
|
||||
#if defined(LTC_MD4)
|
||||
" MD4\n"
|
||||
#endif
|
||||
#if defined(LTC_MD2)
|
||||
" MD2\n"
|
||||
#endif
|
||||
#if defined(LTC_RIPEMD128)
|
||||
" RIPEMD128\n"
|
||||
#endif
|
||||
#if defined(LTC_RIPEMD160)
|
||||
" RIPEMD160\n"
|
||||
#endif
|
||||
#if defined(LTC_RIPEMD256)
|
||||
" RIPEMD256\n"
|
||||
#endif
|
||||
#if defined(LTC_RIPEMD320)
|
||||
" RIPEMD320\n"
|
||||
#endif
|
||||
#if defined(LTC_WHIRLPOOL)
|
||||
" WHIRLPOOL\n"
|
||||
#endif
|
||||
#if defined(LTC_BLAKE2S)
|
||||
" BLAKE2S\n"
|
||||
#endif
|
||||
#if defined(LTC_BLAKE2B)
|
||||
" BLAKE2B\n"
|
||||
#endif
|
||||
#if defined(LTC_CHC_HASH)
|
||||
" CHC_HASH\n"
|
||||
#endif
|
||||
|
||||
"\nBlock Chaining Modes:\n"
|
||||
#if defined(LTC_CFB_MODE)
|
||||
" CFB\n"
|
||||
#endif
|
||||
#if defined(LTC_OFB_MODE)
|
||||
" OFB\n"
|
||||
#endif
|
||||
#if defined(LTC_ECB_MODE)
|
||||
" ECB\n"
|
||||
#endif
|
||||
#if defined(LTC_CBC_MODE)
|
||||
" CBC\n"
|
||||
#endif
|
||||
#if defined(LTC_CTR_MODE)
|
||||
" CTR\n"
|
||||
#endif
|
||||
#if defined(LTC_LRW_MODE)
|
||||
" LRW"
|
||||
#if defined(LTC_LRW_TABLES)
|
||||
" (tables) "
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(LTC_F8_MODE)
|
||||
" F8\n"
|
||||
#endif
|
||||
#if defined(LTC_XTS_MODE)
|
||||
" XTS\n"
|
||||
#endif
|
||||
|
||||
"\nMACs:\n"
|
||||
#if defined(LTC_HMAC)
|
||||
" HMAC\n"
|
||||
#endif
|
||||
#if defined(LTC_OMAC)
|
||||
" OMAC\n"
|
||||
#endif
|
||||
#if defined(LTC_PMAC)
|
||||
" PMAC\n"
|
||||
#endif
|
||||
#if defined(LTC_PELICAN)
|
||||
" PELICAN\n"
|
||||
#endif
|
||||
#if defined(LTC_XCBC)
|
||||
" XCBC\n"
|
||||
#endif
|
||||
#if defined(LTC_F9_MODE)
|
||||
" F9\n"
|
||||
#endif
|
||||
#if defined(LTC_POLY1305)
|
||||
" POLY1305\n"
|
||||
#endif
|
||||
#if defined(LTC_BLAKE2SMAC)
|
||||
" BLAKE2S MAC\n"
|
||||
#endif
|
||||
#if defined(LTC_BLAKE2BMAC)
|
||||
" BLAKE2B MAC\n"
|
||||
#endif
|
||||
|
||||
"\nENC + AUTH modes:\n"
|
||||
#if defined(LTC_EAX_MODE)
|
||||
" EAX\n"
|
||||
#endif
|
||||
#if defined(LTC_OCB_MODE)
|
||||
" OCB\n"
|
||||
#endif
|
||||
#if defined(LTC_OCB3_MODE)
|
||||
" OCB3\n"
|
||||
#endif
|
||||
#if defined(LTC_CCM_MODE)
|
||||
" CCM\n"
|
||||
#endif
|
||||
#if defined(LTC_GCM_MODE)
|
||||
" GCM"
|
||||
#if defined(LTC_GCM_TABLES)
|
||||
" (tables) "
|
||||
#endif
|
||||
#if defined(LTC_GCM_TABLES_SSE2)
|
||||
" (SSE2) "
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(LTC_CHACHA20POLY1305_MODE)
|
||||
" CHACHA20POLY1305\n"
|
||||
#endif
|
||||
|
||||
"\nPRNG:\n"
|
||||
#if defined(LTC_YARROW)
|
||||
" Yarrow ("NAME_VALUE(LTC_YARROW_AES)")\n"
|
||||
#endif
|
||||
#if defined(LTC_SPRNG)
|
||||
" SPRNG\n"
|
||||
#endif
|
||||
#if defined(LTC_RC4)
|
||||
" RC4\n"
|
||||
#endif
|
||||
#if defined(LTC_CHACHA20_PRNG)
|
||||
" ChaCha20\n"
|
||||
#endif
|
||||
#if defined(LTC_FORTUNA)
|
||||
" Fortuna (" NAME_VALUE(LTC_FORTUNA_POOLS) ", " NAME_VALUE(LTC_FORTUNA_WD) ")\n"
|
||||
#endif
|
||||
#if defined(LTC_SOBER128)
|
||||
" SOBER128\n"
|
||||
#endif
|
||||
|
||||
"\nPK Crypto:\n"
|
||||
#if defined(LTC_MRSA)
|
||||
" RSA"
|
||||
#if defined(LTC_RSA_BLINDING) && defined(LTC_RSA_CRT_HARDENING)
|
||||
" (with blinding and CRT hardening)"
|
||||
#elif defined(LTC_RSA_BLINDING)
|
||||
" (with blinding)"
|
||||
#elif defined(LTC_RSA_CRT_HARDENING)
|
||||
" (with CRT hardening)"
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(LTC_MDH)
|
||||
" DH\n"
|
||||
#endif
|
||||
#if defined(LTC_MECC)
|
||||
" ECC"
|
||||
#if defined(LTC_ECC_TIMING_RESISTANT)
|
||||
" (with blinding)"
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(LTC_MDSA)
|
||||
" DSA\n"
|
||||
#endif
|
||||
#if defined(LTC_MKAT)
|
||||
" Katja\n"
|
||||
#endif
|
||||
#if defined(LTC_PK_MAX_RETRIES)
|
||||
" "NAME_VALUE(LTC_PK_MAX_RETRIES)"\n"
|
||||
#endif
|
||||
|
||||
"\nMPI (Math):\n"
|
||||
#if defined(LTC_MPI)
|
||||
" LTC_MPI\n"
|
||||
#endif
|
||||
#if defined(LTM_DESC)
|
||||
" LTM_DESC\n"
|
||||
#endif
|
||||
#if defined(TFM_DESC)
|
||||
" TFM_DESC\n"
|
||||
#endif
|
||||
#if defined(GMP_DESC)
|
||||
" GMP_DESC\n"
|
||||
#endif
|
||||
#if defined(LTC_MILLER_RABIN_REPS)
|
||||
" "NAME_VALUE(LTC_MILLER_RABIN_REPS)"\n"
|
||||
#endif
|
||||
|
||||
"\nCompiler:\n"
|
||||
#if defined(_WIN64)
|
||||
" WIN64 platform detected.\n"
|
||||
#elif defined(_WIN32)
|
||||
" WIN32 platform detected.\n"
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
" CYGWIN Detected.\n"
|
||||
#endif
|
||||
#if defined(__DJGPP__)
|
||||
" DJGPP Detected.\n"
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
" MSVC compiler detected.\n"
|
||||
#endif
|
||||
#if defined(__clang_version__)
|
||||
" Clang compiler " __clang_version__ ".\n"
|
||||
#elif defined(INTEL_CC)
|
||||
" Intel C Compiler " __VERSION__ ".\n"
|
||||
#elif defined(__GNUC__) /* clang and icc also define __GNUC__ */
|
||||
" GCC compiler " __VERSION__ ".\n"
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__)
|
||||
" x86-64 detected.\n"
|
||||
#endif
|
||||
#if defined(LTC_PPC32)
|
||||
" PPC32 detected.\n"
|
||||
#endif
|
||||
|
||||
"\nVarious others: "
|
||||
#if defined(ARGTYPE)
|
||||
" " NAME_VALUE(ARGTYPE) " "
|
||||
#endif
|
||||
#if defined(LTC_ADLER32)
|
||||
" ADLER32 "
|
||||
#endif
|
||||
#if defined(LTC_BASE64)
|
||||
" BASE64 "
|
||||
#endif
|
||||
#if defined(LTC_BASE64_URL)
|
||||
" BASE64-URL-SAFE "
|
||||
#endif
|
||||
#if defined(LTC_CRC32)
|
||||
" CRC32 "
|
||||
#endif
|
||||
#if defined(LTC_DER)
|
||||
" DER "
|
||||
" " NAME_VALUE(LTC_DER_MAX_RECURSION) " "
|
||||
#endif
|
||||
#if defined(LTC_PKCS_1)
|
||||
" PKCS#1 "
|
||||
#endif
|
||||
#if defined(LTC_PKCS_5)
|
||||
" PKCS#5 "
|
||||
#endif
|
||||
#if defined(LTC_HKDF)
|
||||
" HKDF "
|
||||
#endif
|
||||
#if defined(LTC_DEVRANDOM)
|
||||
" LTC_DEVRANDOM "
|
||||
#endif
|
||||
#if defined(LTC_TRY_URANDOM_FIRST)
|
||||
" LTC_TRY_URANDOM_FIRST "
|
||||
#endif
|
||||
#if defined(LTC_RNG_GET_BYTES)
|
||||
" LTC_RNG_GET_BYTES "
|
||||
#endif
|
||||
#if defined(LTC_RNG_MAKE_PRNG)
|
||||
" LTC_RNG_MAKE_PRNG "
|
||||
#endif
|
||||
#if defined(LTC_PRNG_ENABLE_LTC_RNG)
|
||||
" LTC_PRNG_ENABLE_LTC_RNG "
|
||||
#endif
|
||||
#if defined(LTC_HASH_HELPERS)
|
||||
" LTC_HASH_HELPERS "
|
||||
#endif
|
||||
#if defined(LTC_VALGRIND)
|
||||
" LTC_VALGRIND "
|
||||
#endif
|
||||
#if defined(LTC_TEST)
|
||||
" LTC_TEST "
|
||||
#endif
|
||||
#if defined(LTC_TEST_DBG)
|
||||
" " NAME_VALUE(LTC_TEST_DBG) " "
|
||||
#endif
|
||||
#if defined(LTC_TEST_EXT)
|
||||
" LTC_TEST_EXT "
|
||||
#endif
|
||||
#if defined(LTC_SMALL_CODE)
|
||||
" LTC_SMALL_CODE "
|
||||
#endif
|
||||
#if defined(LTC_NO_FILE)
|
||||
" LTC_NO_FILE "
|
||||
#endif
|
||||
#if defined(LTC_FILE_READ_BUFSIZE)
|
||||
" " NAME_VALUE(LTC_FILE_READ_BUFSIZE) " "
|
||||
#endif
|
||||
#if defined(LTC_FAST)
|
||||
" LTC_FAST "
|
||||
#endif
|
||||
#if defined(LTC_NO_FAST)
|
||||
" LTC_NO_FAST "
|
||||
#endif
|
||||
#if defined(LTC_NO_BSWAP)
|
||||
" LTC_NO_BSWAP "
|
||||
#endif
|
||||
#if defined(LTC_NO_ASM)
|
||||
" LTC_NO_ASM "
|
||||
#endif
|
||||
#if defined(LTC_ROx_ASM)
|
||||
" LTC_ROx_ASM "
|
||||
#if defined(LTC_NO_ROLC)
|
||||
" LTC_NO_ROLC "
|
||||
#endif
|
||||
#endif
|
||||
#if defined(LTC_NO_TEST)
|
||||
" LTC_NO_TEST "
|
||||
#endif
|
||||
#if defined(LTC_NO_TABLES)
|
||||
" LTC_NO_TABLES "
|
||||
#endif
|
||||
#if defined(LTC_PTHREAD)
|
||||
" LTC_PTHREAD "
|
||||
#endif
|
||||
#if defined(LTC_EASY)
|
||||
" LTC_EASY "
|
||||
#endif
|
||||
#if defined(LTC_MECC_ACCEL)
|
||||
" LTC_MECC_ACCEL "
|
||||
#endif
|
||||
#if defined(LTC_MECC_FP)
|
||||
" LTC_MECC_FP "
|
||||
#endif
|
||||
#if defined(LTC_ECC_SHAMIR)
|
||||
" LTC_ECC_SHAMIR "
|
||||
#endif
|
||||
"\n"
|
||||
;
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
27
thirdparty/libtomcrypt/misc/crypt/crypt_argchk.c
vendored
Normal file
27
thirdparty/libtomcrypt/misc/crypt/crypt_argchk.c
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/* 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 crypt_argchk.c
|
||||
Perform argument checking, Tom St Denis
|
||||
*/
|
||||
|
||||
#if (ARGTYPE == 0)
|
||||
void crypt_argchk(const char *v, const char *s, int d)
|
||||
{
|
||||
fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n",
|
||||
v, d, s);
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
25
thirdparty/libtomcrypt/misc/crypt/crypt_cipher_descriptor.c
vendored
Normal file
25
thirdparty/libtomcrypt/misc/crypt/crypt_cipher_descriptor.c
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/* 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 crypt_cipher_descriptor.c
|
||||
Stores the cipher descriptor table, Tom St Denis
|
||||
*/
|
||||
|
||||
struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = {
|
||||
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_cipher_mutex)
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
34
thirdparty/libtomcrypt/misc/crypt/crypt_cipher_is_valid.c
vendored
Normal file
34
thirdparty/libtomcrypt/misc/crypt/crypt_cipher_is_valid.c
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/* 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 crypt_cipher_is_valid.c
|
||||
Determine if cipher is valid, Tom St Denis
|
||||
*/
|
||||
|
||||
/*
|
||||
Test if a cipher index is valid
|
||||
@param idx The index of the cipher to search for
|
||||
@return CRYPT_OK if valid
|
||||
*/
|
||||
int cipher_is_valid(int idx)
|
||||
{
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_INVALID_CIPHER;
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
292
thirdparty/libtomcrypt/misc/crypt/crypt_constants.c
vendored
Normal file
292
thirdparty/libtomcrypt/misc/crypt/crypt_constants.c
vendored
Normal file
@ -0,0 +1,292 @@
|
||||
/* 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 crypt_constants.c
|
||||
|
||||
Make various constants available to dynamic languages
|
||||
like Python - Larry Bugbee, February 2013
|
||||
|
||||
LB - Dec 2013 - revised to include compiler define options
|
||||
LB - Mar 2014 - added endianness and word size
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const int value;
|
||||
} crypt_constant;
|
||||
|
||||
#define _C_STRINGIFY(s) { #s, s }
|
||||
|
||||
static const crypt_constant _crypt_constants[] = {
|
||||
|
||||
_C_STRINGIFY(CRYPT_OK),
|
||||
_C_STRINGIFY(CRYPT_ERROR),
|
||||
_C_STRINGIFY(CRYPT_NOP),
|
||||
_C_STRINGIFY(CRYPT_INVALID_KEYSIZE),
|
||||
_C_STRINGIFY(CRYPT_INVALID_ROUNDS),
|
||||
_C_STRINGIFY(CRYPT_FAIL_TESTVECTOR),
|
||||
_C_STRINGIFY(CRYPT_BUFFER_OVERFLOW),
|
||||
_C_STRINGIFY(CRYPT_INVALID_PACKET),
|
||||
_C_STRINGIFY(CRYPT_INVALID_PRNGSIZE),
|
||||
_C_STRINGIFY(CRYPT_ERROR_READPRNG),
|
||||
_C_STRINGIFY(CRYPT_INVALID_CIPHER),
|
||||
_C_STRINGIFY(CRYPT_INVALID_HASH),
|
||||
_C_STRINGIFY(CRYPT_INVALID_PRNG),
|
||||
_C_STRINGIFY(CRYPT_MEM),
|
||||
_C_STRINGIFY(CRYPT_PK_TYPE_MISMATCH),
|
||||
_C_STRINGIFY(CRYPT_PK_NOT_PRIVATE),
|
||||
_C_STRINGIFY(CRYPT_INVALID_ARG),
|
||||
_C_STRINGIFY(CRYPT_FILE_NOTFOUND),
|
||||
_C_STRINGIFY(CRYPT_PK_INVALID_TYPE),
|
||||
_C_STRINGIFY(CRYPT_OVERFLOW),
|
||||
_C_STRINGIFY(CRYPT_UNUSED1),
|
||||
_C_STRINGIFY(CRYPT_INPUT_TOO_LONG),
|
||||
_C_STRINGIFY(CRYPT_PK_INVALID_SIZE),
|
||||
_C_STRINGIFY(CRYPT_INVALID_PRIME_SIZE),
|
||||
_C_STRINGIFY(CRYPT_PK_INVALID_PADDING),
|
||||
_C_STRINGIFY(CRYPT_HASH_OVERFLOW),
|
||||
|
||||
_C_STRINGIFY(PK_PUBLIC),
|
||||
_C_STRINGIFY(PK_PRIVATE),
|
||||
|
||||
_C_STRINGIFY(LTC_ENCRYPT),
|
||||
_C_STRINGIFY(LTC_DECRYPT),
|
||||
|
||||
#ifdef LTC_PKCS_1
|
||||
{"LTC_PKCS_1", 1},
|
||||
/* Block types */
|
||||
_C_STRINGIFY(LTC_PKCS_1_EMSA),
|
||||
_C_STRINGIFY(LTC_PKCS_1_EME),
|
||||
|
||||
/* Padding types */
|
||||
_C_STRINGIFY(LTC_PKCS_1_V1_5),
|
||||
_C_STRINGIFY(LTC_PKCS_1_OAEP),
|
||||
_C_STRINGIFY(LTC_PKCS_1_PSS),
|
||||
_C_STRINGIFY(LTC_PKCS_1_V1_5_NA1),
|
||||
#else
|
||||
{"LTC_PKCS_1", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_MRSA
|
||||
{"LTC_MRSA", 1},
|
||||
#else
|
||||
{"LTC_MRSA", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_MKAT
|
||||
{"LTC_MKAT", 1},
|
||||
_C_STRINGIFY(MIN_KAT_SIZE),
|
||||
_C_STRINGIFY(MAX_KAT_SIZE),
|
||||
#else
|
||||
{"LTC_MKAT", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_MECC
|
||||
{"LTC_MECC", 1},
|
||||
_C_STRINGIFY(ECC_BUF_SIZE),
|
||||
_C_STRINGIFY(ECC_MAXSIZE),
|
||||
#else
|
||||
{"LTC_MECC", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_MDSA
|
||||
{"LTC_MDSA", 1},
|
||||
_C_STRINGIFY(LTC_MDSA_DELTA),
|
||||
_C_STRINGIFY(LTC_MDSA_MAX_GROUP),
|
||||
#else
|
||||
{"LTC_MDSA", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_MILLER_RABIN_REPS
|
||||
_C_STRINGIFY(LTC_MILLER_RABIN_REPS),
|
||||
#endif
|
||||
|
||||
#ifdef LTC_DER
|
||||
/* DER handling */
|
||||
{"LTC_DER", 1},
|
||||
_C_STRINGIFY(LTC_ASN1_EOL),
|
||||
_C_STRINGIFY(LTC_ASN1_BOOLEAN),
|
||||
_C_STRINGIFY(LTC_ASN1_INTEGER),
|
||||
_C_STRINGIFY(LTC_ASN1_SHORT_INTEGER),
|
||||
_C_STRINGIFY(LTC_ASN1_BIT_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_OCTET_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_NULL),
|
||||
_C_STRINGIFY(LTC_ASN1_OBJECT_IDENTIFIER),
|
||||
_C_STRINGIFY(LTC_ASN1_IA5_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_PRINTABLE_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_UTF8_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_UTCTIME),
|
||||
_C_STRINGIFY(LTC_ASN1_CHOICE),
|
||||
_C_STRINGIFY(LTC_ASN1_SEQUENCE),
|
||||
_C_STRINGIFY(LTC_ASN1_SET),
|
||||
_C_STRINGIFY(LTC_ASN1_SETOF),
|
||||
_C_STRINGIFY(LTC_ASN1_RAW_BIT_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_TELETEX_STRING),
|
||||
_C_STRINGIFY(LTC_ASN1_CONSTRUCTED),
|
||||
_C_STRINGIFY(LTC_ASN1_CONTEXT_SPECIFIC),
|
||||
_C_STRINGIFY(LTC_ASN1_GENERALIZEDTIME),
|
||||
_C_STRINGIFY(LTC_DER_MAX_RECURSION),
|
||||
#else
|
||||
{"LTC_DER", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
{"LTC_CTR_MODE", 1},
|
||||
_C_STRINGIFY(CTR_COUNTER_LITTLE_ENDIAN),
|
||||
_C_STRINGIFY(CTR_COUNTER_BIG_ENDIAN),
|
||||
_C_STRINGIFY(LTC_CTR_RFC3686),
|
||||
#else
|
||||
{"LTC_CTR_MODE", 0},
|
||||
#endif
|
||||
#ifdef LTC_GCM_MODE
|
||||
_C_STRINGIFY(LTC_GCM_MODE_IV),
|
||||
_C_STRINGIFY(LTC_GCM_MODE_AAD),
|
||||
_C_STRINGIFY(LTC_GCM_MODE_TEXT),
|
||||
#endif
|
||||
|
||||
_C_STRINGIFY(LTC_MP_LT),
|
||||
_C_STRINGIFY(LTC_MP_EQ),
|
||||
_C_STRINGIFY(LTC_MP_GT),
|
||||
|
||||
_C_STRINGIFY(LTC_MP_NO),
|
||||
_C_STRINGIFY(LTC_MP_YES),
|
||||
|
||||
_C_STRINGIFY(MAXBLOCKSIZE),
|
||||
_C_STRINGIFY(TAB_SIZE),
|
||||
_C_STRINGIFY(ARGTYPE),
|
||||
|
||||
#ifdef LTM_DESC
|
||||
{"LTM_DESC", 1},
|
||||
#else
|
||||
{"LTM_DESC", 0},
|
||||
#endif
|
||||
#ifdef TFM_DESC
|
||||
{"TFM_DESC", 1},
|
||||
#else
|
||||
{"TFM_DESC", 0},
|
||||
#endif
|
||||
#ifdef GMP_DESC
|
||||
{"GMP_DESC", 1},
|
||||
#else
|
||||
{"GMP_DESC", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_FAST
|
||||
{"LTC_FAST", 1},
|
||||
#else
|
||||
{"LTC_FAST", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_NO_FILE
|
||||
{"LTC_NO_FILE", 1},
|
||||
#else
|
||||
{"LTC_NO_FILE", 0},
|
||||
#endif
|
||||
|
||||
#ifdef ENDIAN_LITTLE
|
||||
{"ENDIAN_LITTLE", 1},
|
||||
#else
|
||||
{"ENDIAN_LITTLE", 0},
|
||||
#endif
|
||||
|
||||
#ifdef ENDIAN_BIG
|
||||
{"ENDIAN_BIG", 1},
|
||||
#else
|
||||
{"ENDIAN_BIG", 0},
|
||||
#endif
|
||||
|
||||
#ifdef ENDIAN_32BITWORD
|
||||
{"ENDIAN_32BITWORD", 1},
|
||||
#else
|
||||
{"ENDIAN_32BITWORD", 0},
|
||||
#endif
|
||||
|
||||
#ifdef ENDIAN_64BITWORD
|
||||
{"ENDIAN_64BITWORD", 1},
|
||||
#else
|
||||
{"ENDIAN_64BITWORD", 0},
|
||||
#endif
|
||||
|
||||
#ifdef ENDIAN_NEUTRAL
|
||||
{"ENDIAN_NEUTRAL", 1},
|
||||
#else
|
||||
{"ENDIAN_NEUTRAL", 0},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* crypt_get_constant()
|
||||
* valueout will be the value of the named constant
|
||||
* return -1 if named item not found
|
||||
*/
|
||||
int crypt_get_constant(const char* namein, int *valueout) {
|
||||
int i;
|
||||
int _crypt_constants_len = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
|
||||
for (i=0; i<_crypt_constants_len; i++) {
|
||||
if (XSTRCMP(_crypt_constants[i].name, namein) == 0) {
|
||||
*valueout = _crypt_constants[i].value;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* crypt_list_all_constants()
|
||||
* if names_list is NULL, names_list_size will be the minimum
|
||||
* number of bytes needed to receive the complete names_list
|
||||
* if names_list is NOT NULL, names_list must be the addr of
|
||||
* sufficient memory allocated into which the names_list
|
||||
* is to be written. Also, the value in names_list_size
|
||||
* sets the upper bound of the number of characters to be
|
||||
* written.
|
||||
* a -1 return value signifies insufficient space made available
|
||||
*/
|
||||
int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
|
||||
int i;
|
||||
unsigned int total_len = 0;
|
||||
char *ptr;
|
||||
int number_len;
|
||||
int count = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
|
||||
|
||||
/* calculate amount of memory required for the list */
|
||||
for (i=0; i<count; i++) {
|
||||
number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
|
||||
if (number_len < 0)
|
||||
return -1;
|
||||
total_len += number_len;
|
||||
}
|
||||
|
||||
if (names_list == NULL) {
|
||||
*names_list_size = total_len;
|
||||
} else {
|
||||
if (total_len > *names_list_size) {
|
||||
return -1;
|
||||
}
|
||||
/* build the names list */
|
||||
ptr = names_list;
|
||||
for (i=0; i<count; i++) {
|
||||
number_len = snprintf(ptr, total_len, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
|
||||
if (number_len < 0) return -1;
|
||||
if ((unsigned int)number_len > total_len) return -1;
|
||||
total_len -= number_len;
|
||||
ptr += number_len;
|
||||
}
|
||||
/* to remove the trailing new-line */
|
||||
ptr -= 1;
|
||||
*ptr = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
39
thirdparty/libtomcrypt/misc/crypt/crypt_find_cipher.c
vendored
Normal file
39
thirdparty/libtomcrypt/misc/crypt/crypt_find_cipher.c
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/* 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 crypt_find_cipher.c
|
||||
Find a cipher in the descriptor tables, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a registered cipher by name
|
||||
@param name The name of the cipher to look for
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/
|
||||
int find_cipher(const char *name)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name != NULL && !XSTRCMP(cipher_descriptor[x].name, name)) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
48
thirdparty/libtomcrypt/misc/crypt/crypt_find_cipher_any.c
vendored
Normal file
48
thirdparty/libtomcrypt/misc/crypt/crypt_find_cipher_any.c
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/* 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 crypt_find_cipher_any.c
|
||||
Find a cipher in the descriptor tables, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a cipher flexibly. First by name then if not present by block and key size
|
||||
@param name The name of the cipher desired
|
||||
@param blocklen The minimum length of the block cipher desired (octets)
|
||||
@param keylen The minimum length of the key size desired (octets)
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/
|
||||
int find_cipher_any(const char *name, int blocklen, int keylen)
|
||||
{
|
||||
int x;
|
||||
|
||||
if(name != NULL) {
|
||||
x = find_cipher(name);
|
||||
if (x != -1) return x;
|
||||
}
|
||||
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (blocklen <= (int)cipher_descriptor[x].block_length && keylen <= (int)cipher_descriptor[x].max_key_length) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
38
thirdparty/libtomcrypt/misc/crypt/crypt_find_cipher_id.c
vendored
Normal file
38
thirdparty/libtomcrypt/misc/crypt/crypt_find_cipher_id.c
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/* 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 crypt_find_cipher_id.c
|
||||
Find cipher by ID, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a cipher by ID number
|
||||
@param ID The ID (not same as index) of the cipher to find
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/
|
||||
int find_cipher_id(unsigned char ID)
|
||||
{
|
||||
int x;
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].ID == ID) {
|
||||
x = (cipher_descriptor[x].name == NULL) ? -1 : x;
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
38
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash.c
vendored
Normal file
38
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash.c
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/* 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 crypt_find_hash.c
|
||||
Find a hash, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a registered hash by name
|
||||
@param name The name of the hash to look for
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/
|
||||
int find_hash(const char *name)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name != NULL && XSTRCMP(hash_descriptor[x].name, name) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
47
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash_any.c
vendored
Normal file
47
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash_any.c
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
/* 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 crypt_find_hash_any.c
|
||||
Find a hash, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a hash flexibly. First by name then if not present by digest size
|
||||
@param name The name of the hash desired
|
||||
@param digestlen The minimum length of the digest size (octets)
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/int find_hash_any(const char *name, int digestlen)
|
||||
{
|
||||
int x, y, z;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
|
||||
x = find_hash(name);
|
||||
if (x != -1) return x;
|
||||
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
y = MAXBLOCKSIZE+1;
|
||||
z = -1;
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name == NULL) {
|
||||
continue;
|
||||
}
|
||||
if ((int)hash_descriptor[x].hashsize >= digestlen && (int)hash_descriptor[x].hashsize < y) {
|
||||
z = x;
|
||||
y = hash_descriptor[x].hashsize;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return z;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
38
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash_id.c
vendored
Normal file
38
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash_id.c
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/* 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 crypt_find_hash_id.c
|
||||
Find hash by ID, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a hash by ID number
|
||||
@param ID The ID (not same as index) of the hash to find
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/
|
||||
int find_hash_id(unsigned char ID)
|
||||
{
|
||||
int x;
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].ID == ID) {
|
||||
x = (hash_descriptor[x].name == NULL) ? -1 : x;
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
33
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash_oid.c
vendored
Normal file
33
thirdparty/libtomcrypt/misc/crypt/crypt_find_hash_oid.c
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/* 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 crypt_find_hash_oid.c
|
||||
Find a hash, Tom St Denis
|
||||
*/
|
||||
|
||||
int find_hash_oid(const unsigned long *ID, unsigned long IDlen)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(ID != NULL);
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name != NULL && hash_descriptor[x].OIDlen == IDlen && !XMEMCMP(hash_descriptor[x].OID, ID, sizeof(unsigned long) * IDlen)) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
39
thirdparty/libtomcrypt/misc/crypt/crypt_find_prng.c
vendored
Normal file
39
thirdparty/libtomcrypt/misc/crypt/crypt_find_prng.c
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/* 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 crypt_find_prng.c
|
||||
Find a PRNG, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Find a registered PRNG by name
|
||||
@param name The name of the PRNG to look for
|
||||
@return >= 0 if found, -1 if not present
|
||||
*/
|
||||
int find_prng(const char *name)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if ((prng_descriptor[x].name != NULL) && XSTRCMP(prng_descriptor[x].name, name) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
56
thirdparty/libtomcrypt/misc/crypt/crypt_fsa.c
vendored
Normal file
56
thirdparty/libtomcrypt/misc/crypt/crypt_fsa.c
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/* 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 crypt_fsa.c
|
||||
LibTomCrypt FULL SPEED AHEAD!, Tom St Denis
|
||||
*/
|
||||
|
||||
/* format is ltc_mp, cipher_desc, [cipher_desc], NULL, hash_desc, [hash_desc], NULL, prng_desc, [prng_desc], NULL */
|
||||
int crypt_fsa(void *mp, ...)
|
||||
{
|
||||
va_list args;
|
||||
void *p;
|
||||
|
||||
va_start(args, mp);
|
||||
if (mp != NULL) {
|
||||
XMEMCPY(<c_mp, mp, sizeof(ltc_mp));
|
||||
}
|
||||
|
||||
while ((p = va_arg(args, void*)) != NULL) {
|
||||
if (register_cipher(p) == -1) {
|
||||
va_end(args);
|
||||
return CRYPT_INVALID_CIPHER;
|
||||
}
|
||||
}
|
||||
|
||||
while ((p = va_arg(args, void*)) != NULL) {
|
||||
if (register_hash(p) == -1) {
|
||||
va_end(args);
|
||||
return CRYPT_INVALID_HASH;
|
||||
}
|
||||
}
|
||||
|
||||
while ((p = va_arg(args, void*)) != NULL) {
|
||||
if (register_prng(p) == -1) {
|
||||
va_end(args);
|
||||
return CRYPT_INVALID_PRNG;
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
25
thirdparty/libtomcrypt/misc/crypt/crypt_hash_descriptor.c
vendored
Normal file
25
thirdparty/libtomcrypt/misc/crypt/crypt_hash_descriptor.c
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/* 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 crypt_hash_descriptor.c
|
||||
Stores the hash descriptor table, Tom St Denis
|
||||
*/
|
||||
|
||||
struct ltc_hash_descriptor hash_descriptor[TAB_SIZE] = {
|
||||
{ NULL, 0, 0, 0, { 0 }, 0, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_hash_mutex)
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
34
thirdparty/libtomcrypt/misc/crypt/crypt_hash_is_valid.c
vendored
Normal file
34
thirdparty/libtomcrypt/misc/crypt/crypt_hash_is_valid.c
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/* 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 crypt_hash_is_valid.c
|
||||
Determine if hash is valid, Tom St Denis
|
||||
*/
|
||||
|
||||
/*
|
||||
Test if a hash index is valid
|
||||
@param idx The index of the hash to search for
|
||||
@return CRYPT_OK if valid
|
||||
*/
|
||||
int hash_is_valid(int idx)
|
||||
{
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_INVALID_HASH;
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
43
thirdparty/libtomcrypt/misc/crypt/crypt_inits.c
vendored
Normal file
43
thirdparty/libtomcrypt/misc/crypt/crypt_inits.c
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/* 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 crypt_inits.c
|
||||
|
||||
Provide math library functions for dynamic languages
|
||||
like Python - Larry Bugbee, February 2013
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTM_DESC
|
||||
void init_LTM(void)
|
||||
{
|
||||
ltc_mp = ltm_desc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TFM_DESC
|
||||
void init_TFM(void)
|
||||
{
|
||||
ltc_mp = tfm_desc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GMP_DESC
|
||||
void init_GMP(void)
|
||||
{
|
||||
ltc_mp = gmp_desc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
16
thirdparty/libtomcrypt/misc/crypt/crypt_ltc_mp_descriptor.c
vendored
Normal file
16
thirdparty/libtomcrypt/misc/crypt/crypt_ltc_mp_descriptor.c
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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"
|
||||
|
||||
/* Initialize ltc_mp to nulls, to force allocation on all platforms, including macOS. */
|
||||
ltc_math_descriptor ltc_mp = { 0 };
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
24
thirdparty/libtomcrypt/misc/crypt/crypt_prng_descriptor.c
vendored
Normal file
24
thirdparty/libtomcrypt/misc/crypt/crypt_prng_descriptor.c
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/* 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 crypt_prng_descriptor.c
|
||||
Stores the PRNG descriptors, Tom St Denis
|
||||
*/
|
||||
struct ltc_prng_descriptor prng_descriptor[TAB_SIZE] = {
|
||||
{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_prng_mutex)
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
34
thirdparty/libtomcrypt/misc/crypt/crypt_prng_is_valid.c
vendored
Normal file
34
thirdparty/libtomcrypt/misc/crypt/crypt_prng_is_valid.c
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/* 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 crypt_prng_is_valid.c
|
||||
Determine if PRNG is valid, Tom St Denis
|
||||
*/
|
||||
|
||||
/*
|
||||
Test if a PRNG index is valid
|
||||
@param idx The index of the PRNG to search for
|
||||
@return CRYPT_OK if valid
|
||||
*/
|
||||
int prng_is_valid(int idx)
|
||||
{
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_INVALID_PRNG;
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
17
thirdparty/libtomcrypt/misc/crypt/crypt_prng_rng_descriptor.c
vendored
Normal file
17
thirdparty/libtomcrypt/misc/crypt/crypt_prng_rng_descriptor.c
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/* 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"
|
||||
|
||||
#ifdef LTC_PRNG_ENABLE_LTC_RNG
|
||||
unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
100
thirdparty/libtomcrypt/misc/crypt/crypt_register_all_ciphers.c
vendored
Normal file
100
thirdparty/libtomcrypt/misc/crypt/crypt_register_all_ciphers.c
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
/* 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 crypt_register_all_ciphers.c
|
||||
|
||||
Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#define REGISTER_CIPHER(h) do {\
|
||||
LTC_ARGCHK(register_cipher(h) != -1); \
|
||||
} while(0)
|
||||
|
||||
int register_all_ciphers(void)
|
||||
{
|
||||
#ifdef LTC_RIJNDAEL
|
||||
#ifdef ENCRYPT_ONLY
|
||||
/* alternative would be
|
||||
* register_cipher(&rijndael_enc_desc);
|
||||
*/
|
||||
REGISTER_CIPHER(&aes_enc_desc);
|
||||
#else
|
||||
/* alternative would be
|
||||
* register_cipher(&rijndael_desc);
|
||||
*/
|
||||
REGISTER_CIPHER(&aes_desc);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef LTC_BLOWFISH
|
||||
REGISTER_CIPHER(&blowfish_desc);
|
||||
#endif
|
||||
#ifdef LTC_XTEA
|
||||
REGISTER_CIPHER(&xtea_desc);
|
||||
#endif
|
||||
#ifdef LTC_RC5
|
||||
REGISTER_CIPHER(&rc5_desc);
|
||||
#endif
|
||||
#ifdef LTC_RC6
|
||||
REGISTER_CIPHER(&rc6_desc);
|
||||
#endif
|
||||
#ifdef LTC_SAFERP
|
||||
REGISTER_CIPHER(&saferp_desc);
|
||||
#endif
|
||||
#ifdef LTC_TWOFISH
|
||||
REGISTER_CIPHER(&twofish_desc);
|
||||
#endif
|
||||
#ifdef LTC_SAFER
|
||||
REGISTER_CIPHER(&safer_k64_desc);
|
||||
REGISTER_CIPHER(&safer_sk64_desc);
|
||||
REGISTER_CIPHER(&safer_k128_desc);
|
||||
REGISTER_CIPHER(&safer_sk128_desc);
|
||||
#endif
|
||||
#ifdef LTC_RC2
|
||||
REGISTER_CIPHER(&rc2_desc);
|
||||
#endif
|
||||
#ifdef LTC_DES
|
||||
REGISTER_CIPHER(&des_desc);
|
||||
REGISTER_CIPHER(&des3_desc);
|
||||
#endif
|
||||
#ifdef LTC_CAST5
|
||||
REGISTER_CIPHER(&cast5_desc);
|
||||
#endif
|
||||
#ifdef LTC_NOEKEON
|
||||
REGISTER_CIPHER(&noekeon_desc);
|
||||
#endif
|
||||
#ifdef LTC_SKIPJACK
|
||||
REGISTER_CIPHER(&skipjack_desc);
|
||||
#endif
|
||||
#ifdef LTC_ANUBIS
|
||||
REGISTER_CIPHER(&anubis_desc);
|
||||
#endif
|
||||
#ifdef LTC_KHAZAD
|
||||
REGISTER_CIPHER(&khazad_desc);
|
||||
#endif
|
||||
#ifdef LTC_KSEED
|
||||
REGISTER_CIPHER(&kseed_desc);
|
||||
#endif
|
||||
#ifdef LTC_KASUMI
|
||||
REGISTER_CIPHER(&kasumi_desc);
|
||||
#endif
|
||||
#ifdef LTC_MULTI2
|
||||
REGISTER_CIPHER(&multi2_desc);
|
||||
#endif
|
||||
#ifdef LTC_CAMELLIA
|
||||
REGISTER_CIPHER(&camellia_desc);
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
99
thirdparty/libtomcrypt/misc/crypt/crypt_register_all_hashes.c
vendored
Normal file
99
thirdparty/libtomcrypt/misc/crypt/crypt_register_all_hashes.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 crypt_register_all_hashes.c
|
||||
|
||||
Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#define REGISTER_HASH(h) do {\
|
||||
LTC_ARGCHK(register_hash(h) != -1); \
|
||||
} while(0)
|
||||
|
||||
int register_all_hashes(void)
|
||||
{
|
||||
#ifdef LTC_TIGER
|
||||
REGISTER_HASH(&tiger_desc);
|
||||
#endif
|
||||
#ifdef LTC_MD2
|
||||
REGISTER_HASH(&md2_desc);
|
||||
#endif
|
||||
#ifdef LTC_MD4
|
||||
REGISTER_HASH(&md4_desc);
|
||||
#endif
|
||||
#ifdef LTC_MD5
|
||||
REGISTER_HASH(&md5_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA1
|
||||
REGISTER_HASH(&sha1_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA224
|
||||
REGISTER_HASH(&sha224_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA256
|
||||
REGISTER_HASH(&sha256_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA384
|
||||
REGISTER_HASH(&sha384_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA512
|
||||
REGISTER_HASH(&sha512_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA512_224
|
||||
REGISTER_HASH(&sha512_224_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA512_256
|
||||
REGISTER_HASH(&sha512_256_desc);
|
||||
#endif
|
||||
#ifdef LTC_SHA3
|
||||
REGISTER_HASH(&sha3_224_desc);
|
||||
REGISTER_HASH(&sha3_256_desc);
|
||||
REGISTER_HASH(&sha3_384_desc);
|
||||
REGISTER_HASH(&sha3_512_desc);
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD128
|
||||
REGISTER_HASH(&rmd128_desc);
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD160
|
||||
REGISTER_HASH(&rmd160_desc);
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD256
|
||||
REGISTER_HASH(&rmd256_desc);
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD320
|
||||
REGISTER_HASH(&rmd320_desc);
|
||||
#endif
|
||||
#ifdef LTC_WHIRLPOOL
|
||||
REGISTER_HASH(&whirlpool_desc);
|
||||
#endif
|
||||
#ifdef LTC_BLAKE2S
|
||||
REGISTER_HASH(&blake2s_128_desc);
|
||||
REGISTER_HASH(&blake2s_160_desc);
|
||||
REGISTER_HASH(&blake2s_224_desc);
|
||||
REGISTER_HASH(&blake2s_256_desc);
|
||||
#endif
|
||||
#ifdef LTC_BLAKE2S
|
||||
REGISTER_HASH(&blake2b_160_desc);
|
||||
REGISTER_HASH(&blake2b_256_desc);
|
||||
REGISTER_HASH(&blake2b_384_desc);
|
||||
REGISTER_HASH(&blake2b_512_desc);
|
||||
#endif
|
||||
#ifdef LTC_CHC_HASH
|
||||
REGISTER_HASH(&chc_desc);
|
||||
LTC_ARGCHK(chc_register(find_cipher_any("aes", 8, 16)) == CRYPT_OK);
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
48
thirdparty/libtomcrypt/misc/crypt/crypt_register_all_prngs.c
vendored
Normal file
48
thirdparty/libtomcrypt/misc/crypt/crypt_register_all_prngs.c
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/* 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 crypt_register_all_prngs.c
|
||||
|
||||
Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#define REGISTER_PRNG(h) do {\
|
||||
LTC_ARGCHK(register_prng(h) != -1); \
|
||||
} while(0)
|
||||
|
||||
int register_all_prngs(void)
|
||||
{
|
||||
#ifdef LTC_YARROW
|
||||
REGISTER_PRNG(&yarrow_desc);
|
||||
#endif
|
||||
#ifdef LTC_FORTUNA
|
||||
REGISTER_PRNG(&fortuna_desc);
|
||||
#endif
|
||||
#ifdef LTC_RC4
|
||||
REGISTER_PRNG(&rc4_desc);
|
||||
#endif
|
||||
#ifdef LTC_CHACHA20_PRNG
|
||||
REGISTER_PRNG(&chacha20_prng_desc);
|
||||
#endif
|
||||
#ifdef LTC_SOBER128
|
||||
REGISTER_PRNG(&sober128_desc);
|
||||
#endif
|
||||
#ifdef LTC_SPRNG
|
||||
REGISTER_PRNG(&sprng_desc);
|
||||
#endif
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
52
thirdparty/libtomcrypt/misc/crypt/crypt_register_cipher.c
vendored
Normal file
52
thirdparty/libtomcrypt/misc/crypt/crypt_register_cipher.c
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/* 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 crypt_register_cipher.c
|
||||
Register a cipher, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Register a cipher with the descriptor table
|
||||
@param cipher The cipher you wish to register
|
||||
@return value >= 0 if successfully added (or already present), -1 if unsuccessful
|
||||
*/
|
||||
int register_cipher(const struct ltc_cipher_descriptor *cipher)
|
||||
{
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(cipher != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* find a blank spot */
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name == NULL) {
|
||||
XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor));
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* no spot */
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
52
thirdparty/libtomcrypt/misc/crypt/crypt_register_hash.c
vendored
Normal file
52
thirdparty/libtomcrypt/misc/crypt/crypt_register_hash.c
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/* 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 crypt_register_hash.c
|
||||
Register a HASH, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Register a hash with the descriptor table
|
||||
@param hash The hash you wish to register
|
||||
@return value >= 0 if successfully added (or already present), -1 if unsuccessful
|
||||
*/
|
||||
int register_hash(const struct ltc_hash_descriptor *hash)
|
||||
{
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(hash != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (XMEMCMP(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* find a blank spot */
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name == NULL) {
|
||||
XMEMCPY(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor));
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* no spot */
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
52
thirdparty/libtomcrypt/misc/crypt/crypt_register_prng.c
vendored
Normal file
52
thirdparty/libtomcrypt/misc/crypt/crypt_register_prng.c
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/* 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 crypt_register_prng.c
|
||||
Register a PRNG, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Register a PRNG with the descriptor table
|
||||
@param prng The PRNG you wish to register
|
||||
@return value >= 0 if successfully added (or already present), -1 if unsuccessful
|
||||
*/
|
||||
int register_prng(const struct ltc_prng_descriptor *prng)
|
||||
{
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (XMEMCMP(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* find a blank spot */
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (prng_descriptor[x].name == NULL) {
|
||||
XMEMCPY(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor));
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* no spot */
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
348
thirdparty/libtomcrypt/misc/crypt/crypt_sizes.c
vendored
Normal file
348
thirdparty/libtomcrypt/misc/crypt/crypt_sizes.c
vendored
Normal file
@ -0,0 +1,348 @@
|
||||
/* 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 crypt_sizes.c
|
||||
|
||||
Make various struct sizes available to dynamic languages
|
||||
like Python - Larry Bugbee, February 2013
|
||||
|
||||
LB - Dec 2013 - revised to include compiler define options
|
||||
*/
|
||||
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const unsigned int size;
|
||||
} crypt_size;
|
||||
|
||||
#define _SZ_STRINGIFY_S(s) { #s, sizeof(struct s) }
|
||||
#define _SZ_STRINGIFY_T(s) { #s, sizeof(s) }
|
||||
|
||||
static const crypt_size _crypt_sizes[] = {
|
||||
/* hash state sizes */
|
||||
_SZ_STRINGIFY_S(ltc_hash_descriptor),
|
||||
_SZ_STRINGIFY_T(hash_state),
|
||||
#ifdef LTC_CHC_HASH
|
||||
_SZ_STRINGIFY_S(chc_state),
|
||||
#endif
|
||||
#ifdef LTC_WHIRLPOOL
|
||||
_SZ_STRINGIFY_S(whirlpool_state),
|
||||
#endif
|
||||
#ifdef LTC_SHA3
|
||||
_SZ_STRINGIFY_S(sha3_state),
|
||||
#endif
|
||||
#ifdef LTC_SHA512
|
||||
_SZ_STRINGIFY_S(sha512_state),
|
||||
#endif
|
||||
#ifdef LTC_SHA256
|
||||
_SZ_STRINGIFY_S(sha256_state),
|
||||
#endif
|
||||
#ifdef LTC_SHA1
|
||||
_SZ_STRINGIFY_S(sha1_state),
|
||||
#endif
|
||||
#ifdef LTC_MD5
|
||||
_SZ_STRINGIFY_S(md5_state),
|
||||
#endif
|
||||
#ifdef LTC_MD4
|
||||
_SZ_STRINGIFY_S(md4_state),
|
||||
#endif
|
||||
#ifdef LTC_MD2
|
||||
_SZ_STRINGIFY_S(md2_state),
|
||||
#endif
|
||||
#ifdef LTC_TIGER
|
||||
_SZ_STRINGIFY_S(tiger_state),
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD128
|
||||
_SZ_STRINGIFY_S(rmd128_state),
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD160
|
||||
_SZ_STRINGIFY_S(rmd160_state),
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD256
|
||||
_SZ_STRINGIFY_S(rmd256_state),
|
||||
#endif
|
||||
#ifdef LTC_RIPEMD320
|
||||
_SZ_STRINGIFY_S(rmd320_state),
|
||||
#endif
|
||||
#ifdef LTC_BLAKE2S
|
||||
_SZ_STRINGIFY_S(blake2s_state),
|
||||
#endif
|
||||
#ifdef LTC_BLAKE2B
|
||||
_SZ_STRINGIFY_S(blake2b_state),
|
||||
#endif
|
||||
|
||||
/* block cipher key sizes */
|
||||
_SZ_STRINGIFY_S(ltc_cipher_descriptor),
|
||||
_SZ_STRINGIFY_T(symmetric_key),
|
||||
#ifdef LTC_ANUBIS
|
||||
_SZ_STRINGIFY_S(anubis_key),
|
||||
#endif
|
||||
#ifdef LTC_CAMELLIA
|
||||
_SZ_STRINGIFY_S(camellia_key),
|
||||
#endif
|
||||
#ifdef LTC_BLOWFISH
|
||||
_SZ_STRINGIFY_S(blowfish_key),
|
||||
#endif
|
||||
#ifdef LTC_CAST5
|
||||
_SZ_STRINGIFY_S(cast5_key),
|
||||
#endif
|
||||
#ifdef LTC_DES
|
||||
_SZ_STRINGIFY_S(des_key),
|
||||
_SZ_STRINGIFY_S(des3_key),
|
||||
#endif
|
||||
#ifdef LTC_KASUMI
|
||||
_SZ_STRINGIFY_S(kasumi_key),
|
||||
#endif
|
||||
#ifdef LTC_KHAZAD
|
||||
_SZ_STRINGIFY_S(khazad_key),
|
||||
#endif
|
||||
#ifdef LTC_KSEED
|
||||
_SZ_STRINGIFY_S(kseed_key),
|
||||
#endif
|
||||
#ifdef LTC_MULTI2
|
||||
_SZ_STRINGIFY_S(multi2_key),
|
||||
#endif
|
||||
#ifdef LTC_NOEKEON
|
||||
_SZ_STRINGIFY_S(noekeon_key),
|
||||
#endif
|
||||
#ifdef LTC_RC2
|
||||
_SZ_STRINGIFY_S(rc2_key),
|
||||
#endif
|
||||
#ifdef LTC_RC5
|
||||
_SZ_STRINGIFY_S(rc5_key),
|
||||
#endif
|
||||
#ifdef LTC_RC6
|
||||
_SZ_STRINGIFY_S(rc6_key),
|
||||
#endif
|
||||
#ifdef LTC_SKIPJACK
|
||||
_SZ_STRINGIFY_S(skipjack_key),
|
||||
#endif
|
||||
#ifdef LTC_XTEA
|
||||
_SZ_STRINGIFY_S(xtea_key),
|
||||
#endif
|
||||
#ifdef LTC_RIJNDAEL
|
||||
_SZ_STRINGIFY_S(rijndael_key),
|
||||
#endif
|
||||
#ifdef LTC_SAFER
|
||||
_SZ_STRINGIFY_S(safer_key),
|
||||
#endif
|
||||
#ifdef LTC_SAFERP
|
||||
_SZ_STRINGIFY_S(saferp_key),
|
||||
#endif
|
||||
#ifdef LTC_TWOFISH
|
||||
_SZ_STRINGIFY_S(twofish_key),
|
||||
#endif
|
||||
|
||||
/* mode sizes */
|
||||
#ifdef LTC_ECB_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_ECB),
|
||||
#endif
|
||||
#ifdef LTC_CFB_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_CFB),
|
||||
#endif
|
||||
#ifdef LTC_OFB_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_OFB),
|
||||
#endif
|
||||
#ifdef LTC_CBC_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_CBC),
|
||||
#endif
|
||||
#ifdef LTC_CTR_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_CTR),
|
||||
#endif
|
||||
#ifdef LTC_LRW_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_LRW),
|
||||
#endif
|
||||
#ifdef LTC_F8_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_F8),
|
||||
#endif
|
||||
#ifdef LTC_XTS_MODE
|
||||
_SZ_STRINGIFY_T(symmetric_xts),
|
||||
#endif
|
||||
|
||||
/* stream cipher sizes */
|
||||
#ifdef LTC_CHACHA
|
||||
_SZ_STRINGIFY_T(chacha_state),
|
||||
#endif
|
||||
#ifdef LTC_RC4_STREAM
|
||||
_SZ_STRINGIFY_T(rc4_state),
|
||||
#endif
|
||||
#ifdef LTC_SOBER128_STREAM
|
||||
_SZ_STRINGIFY_T(sober128_state),
|
||||
#endif
|
||||
|
||||
/* MAC sizes -- no states for ccm, lrw */
|
||||
#ifdef LTC_HMAC
|
||||
_SZ_STRINGIFY_T(hmac_state),
|
||||
#endif
|
||||
#ifdef LTC_OMAC
|
||||
_SZ_STRINGIFY_T(omac_state),
|
||||
#endif
|
||||
#ifdef LTC_PMAC
|
||||
_SZ_STRINGIFY_T(pmac_state),
|
||||
#endif
|
||||
#ifdef LTC_POLY1305
|
||||
_SZ_STRINGIFY_T(poly1305_state),
|
||||
#endif
|
||||
#ifdef LTC_EAX_MODE
|
||||
_SZ_STRINGIFY_T(eax_state),
|
||||
#endif
|
||||
#ifdef LTC_OCB_MODE
|
||||
_SZ_STRINGIFY_T(ocb_state),
|
||||
#endif
|
||||
#ifdef LTC_OCB3_MODE
|
||||
_SZ_STRINGIFY_T(ocb3_state),
|
||||
#endif
|
||||
#ifdef LTC_CCM_MODE
|
||||
_SZ_STRINGIFY_T(ccm_state),
|
||||
#endif
|
||||
#ifdef LTC_GCM_MODE
|
||||
_SZ_STRINGIFY_T(gcm_state),
|
||||
#endif
|
||||
#ifdef LTC_PELICAN
|
||||
_SZ_STRINGIFY_T(pelican_state),
|
||||
#endif
|
||||
#ifdef LTC_XCBC
|
||||
_SZ_STRINGIFY_T(xcbc_state),
|
||||
#endif
|
||||
#ifdef LTC_F9_MODE
|
||||
_SZ_STRINGIFY_T(f9_state),
|
||||
#endif
|
||||
#ifdef LTC_CHACHA20POLY1305_MODE
|
||||
_SZ_STRINGIFY_T(chacha20poly1305_state),
|
||||
#endif
|
||||
|
||||
/* asymmetric keys */
|
||||
#ifdef LTC_MRSA
|
||||
_SZ_STRINGIFY_T(rsa_key),
|
||||
#endif
|
||||
#ifdef LTC_MDSA
|
||||
_SZ_STRINGIFY_T(dsa_key),
|
||||
#endif
|
||||
#ifdef LTC_MDH
|
||||
_SZ_STRINGIFY_T(dh_key),
|
||||
#endif
|
||||
#ifdef LTC_MECC
|
||||
_SZ_STRINGIFY_T(ltc_ecc_set_type),
|
||||
_SZ_STRINGIFY_T(ecc_point),
|
||||
_SZ_STRINGIFY_T(ecc_key),
|
||||
#endif
|
||||
#ifdef LTC_MKAT
|
||||
_SZ_STRINGIFY_T(katja_key),
|
||||
#endif
|
||||
|
||||
/* DER handling */
|
||||
#ifdef LTC_DER
|
||||
_SZ_STRINGIFY_T(ltc_asn1_list), /* a list entry */
|
||||
_SZ_STRINGIFY_T(ltc_utctime),
|
||||
_SZ_STRINGIFY_T(ltc_generalizedtime),
|
||||
#endif
|
||||
|
||||
/* prng state sizes */
|
||||
_SZ_STRINGIFY_S(ltc_prng_descriptor),
|
||||
_SZ_STRINGIFY_T(prng_state),
|
||||
#ifdef LTC_FORTUNA
|
||||
_SZ_STRINGIFY_S(fortuna_prng),
|
||||
#endif
|
||||
#ifdef LTC_CHACHA20_PRNG
|
||||
_SZ_STRINGIFY_S(chacha20_prng),
|
||||
#endif
|
||||
#ifdef LTC_RC4
|
||||
_SZ_STRINGIFY_S(rc4_prng),
|
||||
#endif
|
||||
#ifdef LTC_SOBER128
|
||||
_SZ_STRINGIFY_S(sober128_prng),
|
||||
#endif
|
||||
#ifdef LTC_YARROW
|
||||
_SZ_STRINGIFY_S(yarrow_prng),
|
||||
#endif
|
||||
/* sprng has no state as it uses other potentially available sources */
|
||||
/* like /dev/random. See Developers Guide for more info. */
|
||||
|
||||
#ifdef LTC_ADLER32
|
||||
_SZ_STRINGIFY_T(adler32_state),
|
||||
#endif
|
||||
#ifdef LTC_CRC32
|
||||
_SZ_STRINGIFY_T(crc32_state),
|
||||
#endif
|
||||
|
||||
_SZ_STRINGIFY_T(ltc_mp_digit),
|
||||
_SZ_STRINGIFY_T(ltc_math_descriptor)
|
||||
|
||||
};
|
||||
|
||||
/* crypt_get_size()
|
||||
* sizeout will be the size (bytes) of the named struct or union
|
||||
* return -1 if named item not found
|
||||
*/
|
||||
int crypt_get_size(const char* namein, unsigned int *sizeout) {
|
||||
int i;
|
||||
int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
|
||||
for (i=0; i<count; i++) {
|
||||
if (XSTRCMP(_crypt_sizes[i].name, namein) == 0) {
|
||||
*sizeout = _crypt_sizes[i].size;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* crypt_list_all_sizes()
|
||||
* if names_list is NULL, names_list_size will be the minimum
|
||||
* size needed to receive the complete names_list
|
||||
* if names_list is NOT NULL, names_list must be the addr with
|
||||
* sufficient memory allocated into which the names_list
|
||||
* is to be written. Also, the value in names_list_size
|
||||
* sets the upper bound of the number of characters to be
|
||||
* written.
|
||||
* a -1 return value signifies insufficient space made available
|
||||
*/
|
||||
int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
|
||||
int i;
|
||||
unsigned int total_len = 0;
|
||||
char *ptr;
|
||||
int number_len;
|
||||
int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
|
||||
|
||||
/* calculate amount of memory required for the list */
|
||||
for (i=0; i<count; i++) {
|
||||
number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
|
||||
if (number_len < 0)
|
||||
return -1;
|
||||
total_len += number_len;
|
||||
/* this last +1 is for newlines (and ending NULL) */
|
||||
}
|
||||
|
||||
if (names_list == NULL) {
|
||||
*names_list_size = total_len;
|
||||
} else {
|
||||
if (total_len > *names_list_size) {
|
||||
return -1;
|
||||
}
|
||||
/* build the names list */
|
||||
ptr = names_list;
|
||||
for (i=0; i<count; i++) {
|
||||
number_len = snprintf(ptr, total_len, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
|
||||
if (number_len < 0) return -1;
|
||||
if ((unsigned int)number_len > total_len) return -1;
|
||||
total_len -= number_len;
|
||||
ptr += number_len;
|
||||
}
|
||||
/* to remove the trailing new-line */
|
||||
ptr -= 1;
|
||||
*ptr = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
43
thirdparty/libtomcrypt/misc/crypt/crypt_unregister_cipher.c
vendored
Normal file
43
thirdparty/libtomcrypt/misc/crypt/crypt_unregister_cipher.c
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/* 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 crypt_unregister_cipher.c
|
||||
Unregister a cipher, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Unregister a cipher from the descriptor table
|
||||
@param cipher The cipher descriptor to remove
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int unregister_cipher(const struct ltc_cipher_descriptor *cipher)
|
||||
{
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(cipher != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (XMEMCMP(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor)) == 0) {
|
||||
cipher_descriptor[x].name = NULL;
|
||||
cipher_descriptor[x].ID = 255;
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
42
thirdparty/libtomcrypt/misc/crypt/crypt_unregister_hash.c
vendored
Normal file
42
thirdparty/libtomcrypt/misc/crypt/crypt_unregister_hash.c
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/* 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 crypt_unregister_hash.c
|
||||
Unregister a hash, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Unregister a hash from the descriptor table
|
||||
@param hash The hash descriptor to remove
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int unregister_hash(const struct ltc_hash_descriptor *hash)
|
||||
{
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(hash != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (XMEMCMP(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
|
||||
hash_descriptor[x].name = NULL;
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
42
thirdparty/libtomcrypt/misc/crypt/crypt_unregister_prng.c
vendored
Normal file
42
thirdparty/libtomcrypt/misc/crypt/crypt_unregister_prng.c
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/* 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 crypt_unregister_prng.c
|
||||
Unregister a PRNG, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Unregister a PRNG from the descriptor table
|
||||
@param prng The PRNG descriptor to remove
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int unregister_prng(const struct ltc_prng_descriptor *prng)
|
||||
{
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (XMEMCMP(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {
|
||||
prng_descriptor[x].name = NULL;
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
79
thirdparty/libtomcrypt/misc/error_to_string.c
vendored
Normal file
79
thirdparty/libtomcrypt/misc/error_to_string.c
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/* 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 error_to_string.c
|
||||
Convert error codes to ASCII strings, Tom St Denis
|
||||
*/
|
||||
|
||||
static const char * const err_2_str[] =
|
||||
{
|
||||
"CRYPT_OK",
|
||||
"CRYPT_ERROR",
|
||||
"Non-fatal 'no-operation' requested.",
|
||||
|
||||
"Invalid key size.",
|
||||
"Invalid number of rounds for block cipher.",
|
||||
"Algorithm failed test vectors.",
|
||||
|
||||
"Buffer overflow.",
|
||||
"Invalid input packet.",
|
||||
|
||||
"Invalid number of bits for a PRNG.",
|
||||
"Error reading the PRNG.",
|
||||
|
||||
"Invalid cipher specified.",
|
||||
"Invalid hash specified.",
|
||||
"Invalid PRNG specified.",
|
||||
|
||||
"Out of memory.",
|
||||
|
||||
"Invalid PK key or key type specified for function.",
|
||||
"A private PK key is required.",
|
||||
|
||||
"Invalid argument provided.",
|
||||
"File Not Found",
|
||||
|
||||
"Invalid PK type.",
|
||||
|
||||
"An overflow of a value was detected/prevented.",
|
||||
|
||||
"UNUSED1.",
|
||||
|
||||
"The input was longer than expected.",
|
||||
|
||||
"Invalid sized parameter.",
|
||||
|
||||
"Invalid size for prime.",
|
||||
|
||||
"Invalid padding.",
|
||||
|
||||
"Hash applied to too many bits.",
|
||||
};
|
||||
|
||||
/**
|
||||
Convert an LTC error code to ASCII
|
||||
@param err The error code
|
||||
@return A pointer to the ASCII NUL terminated string for the error or "Invalid error code." if the err code was not valid.
|
||||
*/
|
||||
const char *error_to_string(int err)
|
||||
{
|
||||
if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) {
|
||||
return "Invalid error code.";
|
||||
} else {
|
||||
return err_2_str[err];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
143
thirdparty/libtomcrypt/misc/hkdf/hkdf.c
vendored
Normal file
143
thirdparty/libtomcrypt/misc/hkdf/hkdf.c
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
/* 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 <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#ifdef LTC_HKDF
|
||||
|
||||
/* This is mostly just a wrapper around hmac_memory */
|
||||
int hkdf_extract(int hash_idx, const unsigned char *salt, unsigned long saltlen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
/* libtomcrypt chokes on a zero length HMAC key, so we need to check for
|
||||
that. HMAC specifies that keys shorter than the hash's blocksize are
|
||||
0 padded to the block size. HKDF specifies that a NULL salt is to be
|
||||
substituted with a salt comprised of hashLen 0 bytes. HMAC's padding
|
||||
means that in either case the HMAC is actually using a blocksize long
|
||||
zero filled key. Unless blocksize < hashLen (which wouldn't make any
|
||||
sense), we can use a single 0 byte as the HMAC key and still generate
|
||||
valid results for HKDF. */
|
||||
if (salt == NULL || saltlen == 0) {
|
||||
return hmac_memory(hash_idx, (const unsigned char *)"", 1, in, inlen, out, outlen);
|
||||
} else {
|
||||
return hmac_memory(hash_idx, salt, saltlen, in, inlen, out, outlen);
|
||||
}
|
||||
}
|
||||
|
||||
int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long outlen)
|
||||
{
|
||||
unsigned long hashsize;
|
||||
int err;
|
||||
unsigned char N;
|
||||
unsigned long Noutlen, outoff;
|
||||
|
||||
unsigned char *T, *dat;
|
||||
unsigned long Tlen, datlen;
|
||||
|
||||
/* make sure hash descriptor is valid */
|
||||
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
hashsize = hash_descriptor[hash_idx].hashsize;
|
||||
|
||||
/* RFC5869 parameter restrictions */
|
||||
if (inlen < hashsize || outlen > hashsize * 255)
|
||||
return CRYPT_INVALID_ARG;
|
||||
if (info == NULL && infolen != 0)
|
||||
return CRYPT_INVALID_ARG;
|
||||
LTC_ARGCHK(out != NULL);
|
||||
|
||||
Tlen = hashsize + infolen + 1;
|
||||
T = XMALLOC(Tlen); /* Replace with static buffer? */
|
||||
if (T == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
if (info != NULL) {
|
||||
XMEMCPY(T + hashsize, info, infolen);
|
||||
}
|
||||
|
||||
/* HMAC data T(1) doesn't include a previous hash value */
|
||||
dat = T + hashsize;
|
||||
datlen = Tlen - hashsize;
|
||||
|
||||
N = 0;
|
||||
outoff = 0; /* offset in out to write to */
|
||||
while (1) { /* an exit condition breaks mid-loop */
|
||||
Noutlen = MIN(hashsize, outlen - outoff);
|
||||
T[Tlen - 1] = ++N;
|
||||
if ((err = hmac_memory(hash_idx, in, inlen, dat, datlen,
|
||||
out + outoff, &Noutlen)) != CRYPT_OK) {
|
||||
zeromem(T, Tlen);
|
||||
XFREE(T);
|
||||
return err;
|
||||
}
|
||||
outoff += Noutlen;
|
||||
|
||||
if (outoff >= outlen) /* loop exit condition */
|
||||
break;
|
||||
|
||||
/* All subsequent HMAC data T(N) DOES include the previous hash value */
|
||||
XMEMCPY(T, out + hashsize * (N-1), hashsize);
|
||||
if (N == 1) {
|
||||
dat = T;
|
||||
datlen = Tlen;
|
||||
}
|
||||
}
|
||||
zeromem(T, Tlen);
|
||||
XFREE(T);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* all in one step */
|
||||
int hkdf(int hash_idx, const unsigned char *salt, unsigned long saltlen,
|
||||
const unsigned char *info, unsigned long infolen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long outlen)
|
||||
{
|
||||
unsigned long hashsize;
|
||||
int err;
|
||||
unsigned char *extracted;
|
||||
|
||||
/* make sure hash descriptor is valid */
|
||||
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
hashsize = hash_descriptor[hash_idx].hashsize;
|
||||
|
||||
extracted = XMALLOC(hashsize); /* replace with static buffer? */
|
||||
if (extracted == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
if ((err = hkdf_extract(hash_idx, salt, saltlen, in, inlen, extracted, &hashsize)) != 0) {
|
||||
zeromem(extracted, hashsize);
|
||||
XFREE(extracted);
|
||||
return err;
|
||||
}
|
||||
err = hkdf_expand(hash_idx, info, infolen, extracted, hashsize, out, outlen);
|
||||
zeromem(extracted, hashsize);
|
||||
XFREE(extracted);
|
||||
return err;
|
||||
}
|
||||
#endif /* LTC_HKDF */
|
||||
|
||||
|
||||
/* vim: set ts=2 sw=2 et ai si: */
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
294
thirdparty/libtomcrypt/misc/hkdf/hkdf_test.c
vendored
Normal file
294
thirdparty/libtomcrypt/misc/hkdf/hkdf_test.c
vendored
Normal file
@ -0,0 +1,294 @@
|
||||
/* 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 hkdf_test.c
|
||||
LTC_HKDF support, self-test, Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#ifdef LTC_HKDF
|
||||
|
||||
/*
|
||||
TEST CASES SOURCE:
|
||||
|
||||
Internet Engineering Task Force (IETF) H. Krawczyk
|
||||
Request for Comments: 5869 IBM Research
|
||||
Category: Informational P. Eronen
|
||||
ISSN: 2070-1721 Nokia
|
||||
May 2010
|
||||
Appendix A. Test Vectors
|
||||
*/
|
||||
|
||||
/**
|
||||
LTC_HKDF self-test
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled.
|
||||
*/
|
||||
int hkdf_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
unsigned char OKM[82];
|
||||
int i;
|
||||
|
||||
static const struct hkdf_test_case {
|
||||
int num;
|
||||
const char* Hash;
|
||||
unsigned char IKM[80];
|
||||
unsigned long IKM_l;
|
||||
unsigned char salt[80];
|
||||
unsigned long salt_l;
|
||||
unsigned char info[80];
|
||||
unsigned long info_l;
|
||||
unsigned char PRK[32];
|
||||
unsigned long PRK_l;
|
||||
unsigned char OKM[82];
|
||||
unsigned long OKM_l;
|
||||
} cases[] = {
|
||||
#ifdef LTC_SHA256
|
||||
/*
|
||||
Basic test case with SHA-256
|
||||
|
||||
Hash = SHA-256
|
||||
IKM = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b (22 octets)
|
||||
salt = 0x000102030405060708090a0b0c (13 octets)
|
||||
info = 0xf0f1f2f3f4f5f6f7f8f9 (10 octets)
|
||||
L = 42
|
||||
|
||||
PRK = 0x077709362c2e32df0ddc3f0dc47bba63
|
||||
90b6c73bb50f9c3122ec844ad7c2b3e5 (32 octets)
|
||||
OKM = 0x3cb25f25faacd57a90434f64d0362f2a
|
||||
2d2d0a90cf1a5a4c5db02d56ecc4c5bf
|
||||
34007208d5b887185865 (42 octets)
|
||||
*/
|
||||
{1, "sha256",
|
||||
{0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 22,
|
||||
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c}, 13,
|
||||
{0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9}, 10,
|
||||
{0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf,
|
||||
0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63,
|
||||
0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31,
|
||||
0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5}, 32,
|
||||
{0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
|
||||
0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
|
||||
0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
|
||||
0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
|
||||
0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
|
||||
0x58, 0x65}, 42},
|
||||
#ifdef LTC_TEST_EXT
|
||||
/* Test with SHA-256 and longer inputs/outputs */
|
||||
{2, "sha256",
|
||||
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}, 80,
|
||||
{0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf}, 80,
|
||||
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}, 80,
|
||||
{0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a,
|
||||
0x06, 0x10, 0x4c, 0x9c, 0xeb, 0x35, 0xb4, 0x5c,
|
||||
0xef, 0x76, 0x00, 0x14, 0x90, 0x46, 0x71, 0x01,
|
||||
0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f, 0xc2, 0x44}, 32,
|
||||
{0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1,
|
||||
0xc8, 0xe7, 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34,
|
||||
0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 0xfa, 0xd8,
|
||||
0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c,
|
||||
0x59, 0x04, 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72,
|
||||
0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 0x0e, 0x09,
|
||||
0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8,
|
||||
0x36, 0x77, 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71,
|
||||
0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, 0x3e, 0x87,
|
||||
0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f,
|
||||
0x1d, 0x87}, 82},
|
||||
/* Test with SHA-256 and zero length salt/info */
|
||||
{3, "sha256",
|
||||
{0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 22,
|
||||
{0}, 0,
|
||||
{0}, 0,
|
||||
{0x19, 0xef, 0x24, 0xa3, 0x2c, 0x71, 0x7b, 0x16,
|
||||
0x7f, 0x33, 0xa9, 0x1d, 0x6f, 0x64, 0x8b, 0xdf,
|
||||
0x96, 0x59, 0x67, 0x76, 0xaf, 0xdb, 0x63, 0x77,
|
||||
0xac, 0x43, 0x4c, 0x1c, 0x29, 0x3c, 0xcb, 0x04}, 32,
|
||||
{0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
|
||||
0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
|
||||
0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
|
||||
0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
|
||||
0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
|
||||
0x96, 0xc8}, 42},
|
||||
#endif /* LTC_TEST_EXT */
|
||||
#endif /* LTC_SHA256 */
|
||||
#ifdef LTC_SHA1
|
||||
/* Basic test case with SHA-1 */
|
||||
{4, "sha1",
|
||||
{0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b}, 11,
|
||||
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c}, 13,
|
||||
{0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9}, 10,
|
||||
{0x9b, 0x6c, 0x18, 0xc4, 0x32, 0xa7, 0xbf, 0x8f,
|
||||
0x0e, 0x71, 0xc8, 0xeb, 0x88, 0xf4, 0xb3, 0x0b,
|
||||
0xaa, 0x2b, 0xa2, 0x43}, 20,
|
||||
{0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
|
||||
0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
|
||||
0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
|
||||
0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
|
||||
0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
|
||||
0xf8, 0x96}, 42},
|
||||
#ifdef LTC_TEST_EXT
|
||||
/* Test with SHA-1 and longer inputs/outputs */
|
||||
{5, "sha1",
|
||||
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}, 80,
|
||||
{0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf}, 80,
|
||||
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}, 80,
|
||||
{0x8a, 0xda, 0xe0, 0x9a, 0x2a, 0x30, 0x70, 0x59,
|
||||
0x47, 0x8d, 0x30, 0x9b, 0x26, 0xc4, 0x11, 0x5a,
|
||||
0x22, 0x4c, 0xfa, 0xf6}, 20,
|
||||
{0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7,
|
||||
0xc9, 0xf1, 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb,
|
||||
0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, 0x92, 0x19,
|
||||
0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe,
|
||||
0x8f, 0xa3, 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3,
|
||||
0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, 0x17, 0x3c,
|
||||
0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed,
|
||||
0x03, 0x4c, 0x7f, 0x9d, 0xfe, 0xb1, 0x5c, 0x5e,
|
||||
0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f, 0x4c, 0x43,
|
||||
0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52,
|
||||
0xd3, 0xb4}, 82},
|
||||
/* Test with SHA-1 and zero-length salt/info */
|
||||
{6, "sha1",
|
||||
{0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 22,
|
||||
{0}, 0,
|
||||
{0}, 0,
|
||||
{0xda, 0x8c, 0x8a, 0x73, 0xc7, 0xfa, 0x77, 0x28,
|
||||
0x8e, 0xc6, 0xf5, 0xe7, 0xc2, 0x97, 0x78, 0x6a,
|
||||
0xa0, 0xd3, 0x2d, 0x01}, 20,
|
||||
{0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
|
||||
0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
|
||||
0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
|
||||
0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
|
||||
0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
|
||||
0x49, 0x18}, 42},
|
||||
/* Test with SHA-1, salt not provided (defaults to HashLen zero octets),
|
||||
zero-length info */
|
||||
{7, "sha1",
|
||||
{0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
|
||||
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
|
||||
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c}, 22,
|
||||
{0}, 0, /* pass a null pointer */
|
||||
{0}, 0,
|
||||
{0x2a, 0xdc, 0xca, 0xda, 0x18, 0x77, 0x9e, 0x7c,
|
||||
0x20, 0x77, 0xad, 0x2e, 0xb1, 0x9d, 0x3f, 0x3e,
|
||||
0x73, 0x13, 0x85, 0xdd}, 20,
|
||||
{0x2c, 0x91, 0x11, 0x72, 0x04, 0xd7, 0x45, 0xf3,
|
||||
0x50, 0x0d, 0x63, 0x6a, 0x62, 0xf6, 0x4f, 0x0a,
|
||||
0xb3, 0xba, 0xe5, 0x48, 0xaa, 0x53, 0xd4, 0x23,
|
||||
0xb0, 0xd1, 0xf2, 0x7e, 0xbb, 0xa6, 0xf5, 0xe5,
|
||||
0x67, 0x3a, 0x08, 0x1d, 0x70, 0xcc, 0xe7, 0xac,
|
||||
0xfc, 0x48}, 42},
|
||||
#endif /* LTC_TEST_EXT */
|
||||
#endif /* LTC_SHA1 */
|
||||
};
|
||||
|
||||
int err;
|
||||
int tested=0,failed=0;
|
||||
for(i=0; i < (int)(sizeof(cases) / sizeof(cases[0])); i++) {
|
||||
int hash = find_hash(cases[i].Hash);
|
||||
if (hash == -1) continue;
|
||||
++tested;
|
||||
if((err = hkdf(hash, cases[i].salt, cases[i].salt_l,
|
||||
cases[i].info, cases[i].info_l,
|
||||
cases[i].IKM, cases[i].IKM_l,
|
||||
OKM, cases[i].OKM_l)) != CRYPT_OK) {
|
||||
#if defined(LTC_TEST_DBG) && (LTC_TEST_DBG > 1)
|
||||
printf("LTC_HKDF-%s test #%d, %s\n", cases[i].Hash, i, error_to_string(err));
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
if(compare_testvector(OKM, cases[i].OKM_l, cases[i].OKM, (size_t)cases[i].OKM_l, "HKDF", cases[i].num)) {
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
} else if (tested == 0) {
|
||||
return CRYPT_NOP;
|
||||
} else {
|
||||
return CRYPT_OK;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
63
thirdparty/libtomcrypt/misc/mem_neq.c
vendored
Normal file
63
thirdparty/libtomcrypt/misc/mem_neq.c
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/* 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 mem_neq.c
|
||||
Compare two blocks of memory for inequality in constant time.
|
||||
Steffen Jaeckel
|
||||
*/
|
||||
|
||||
/**
|
||||
Compare two blocks of memory for inequality in constant time.
|
||||
|
||||
The usage is similar to that of standard memcmp, but you can only test
|
||||
if the memory is equal or not - you can not determine by how much the
|
||||
first different byte differs.
|
||||
|
||||
This function shall be used to compare results of cryptographic
|
||||
operations where inequality means most likely usage of a wrong key.
|
||||
The execution time has therefore to be constant as otherwise
|
||||
timing attacks could be possible.
|
||||
|
||||
@param a The first memory region
|
||||
@param b The second memory region
|
||||
@param len The length of the area to compare (octets)
|
||||
|
||||
@return 0 when a and b are equal for len bytes, 1 they are not equal.
|
||||
*/
|
||||
int mem_neq(const void *a, const void *b, size_t len)
|
||||
{
|
||||
unsigned char ret = 0;
|
||||
const unsigned char* pa;
|
||||
const unsigned char* pb;
|
||||
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(b != NULL);
|
||||
|
||||
pa = a;
|
||||
pb = b;
|
||||
|
||||
while (len-- > 0) {
|
||||
ret |= *pa ^ *pb;
|
||||
++pa;
|
||||
++pb;
|
||||
}
|
||||
|
||||
ret |= ret >> 4;
|
||||
ret |= ret >> 2;
|
||||
ret |= ret >> 1;
|
||||
ret &= 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
44
thirdparty/libtomcrypt/misc/pk_get_oid.c
vendored
Normal file
44
thirdparty/libtomcrypt/misc/pk_get_oid.c
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* 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"
|
||||
|
||||
#ifdef LTC_DER
|
||||
static const oid_st rsa_oid = {
|
||||
{ 1, 2, 840, 113549, 1, 1, 1 },
|
||||
7,
|
||||
};
|
||||
|
||||
static const oid_st dsa_oid = {
|
||||
{ 1, 2, 840, 10040, 4, 1 },
|
||||
6,
|
||||
};
|
||||
|
||||
/*
|
||||
Returns the OID of the public key algorithm.
|
||||
@return CRYPT_OK if valid
|
||||
*/
|
||||
int pk_get_oid(int pk, oid_st *st)
|
||||
{
|
||||
switch (pk) {
|
||||
case PKA_RSA:
|
||||
XMEMCPY(st, &rsa_oid, sizeof(*st));
|
||||
break;
|
||||
case PKA_DSA:
|
||||
XMEMCPY(st, &dsa_oid, sizeof(*st));
|
||||
break;
|
||||
default:
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
187
thirdparty/libtomcrypt/misc/pkcs5/pkcs_5_1.c
vendored
Normal file
187
thirdparty/libtomcrypt/misc/pkcs5/pkcs_5_1.c
vendored
Normal file
@ -0,0 +1,187 @@
|
||||
/* 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 pkcs_5_1.c
|
||||
PKCS #5, Algorithm #1, Tom St Denis
|
||||
*/
|
||||
#ifdef LTC_PKCS_5
|
||||
/**
|
||||
Execute PKCS #5 v1 in strict or OpenSSL EVP_BytesToKey()-compat mode.
|
||||
|
||||
PKCS#5 v1 specifies that the output key length can be no larger than
|
||||
the hash output length. OpenSSL unilaterally extended that by repeating
|
||||
the hash process on a block-by-block basis for as long as needed to make
|
||||
bigger keys. If you want to be compatible with KDF for e.g. "openssl enc",
|
||||
you'll want that.
|
||||
|
||||
If you want strict PKCS behavior, turn openssl_compat off. Or (more
|
||||
likely), use one of the convenience functions below.
|
||||
|
||||
@param password The password (or key)
|
||||
@param password_len The length of the password (octet)
|
||||
@param salt The salt (or nonce) which is 8 octets long
|
||||
@param iteration_count The PKCS #5 v1 iteration count
|
||||
@param hash_idx The index of the hash desired
|
||||
@param out [out] The destination for this algorithm
|
||||
@param outlen [in/out] The max size and resulting size of the algorithm output
|
||||
@param openssl_compat [in] Whether or not to grow the key to the buffer size ala OpenSSL
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
static int _pkcs_5_alg1_common(const unsigned char *password,
|
||||
unsigned long password_len,
|
||||
const unsigned char *salt,
|
||||
int iteration_count, int hash_idx,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
int openssl_compat)
|
||||
{
|
||||
int err;
|
||||
unsigned long x;
|
||||
hash_state *md;
|
||||
unsigned char *buf;
|
||||
/* Storage vars in case we need to support > hashsize (OpenSSL compat) */
|
||||
unsigned long block = 0, iter;
|
||||
/* How many bytes to put in the outbut buffer (convenience calc) */
|
||||
unsigned long outidx = 0, nb = 0;
|
||||
|
||||
LTC_ARGCHK(password != NULL);
|
||||
LTC_ARGCHK(salt != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* test hash IDX */
|
||||
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* allocate memory */
|
||||
md = XMALLOC(sizeof(hash_state));
|
||||
buf = XMALLOC(MAXBLOCKSIZE);
|
||||
if (md == NULL || buf == NULL) {
|
||||
if (md != NULL) {
|
||||
XFREE(md);
|
||||
}
|
||||
if (buf != NULL) {
|
||||
XFREE(buf);
|
||||
}
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
while(block * hash_descriptor[hash_idx].hashsize < *outlen) {
|
||||
|
||||
/* hash initial (maybe previous hash) + password + salt */
|
||||
if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
/* in OpenSSL mode, we first hash the previous result for blocks 2-n */
|
||||
if (openssl_compat && block) {
|
||||
if ((err = hash_descriptor[hash_idx].process(md, buf, hash_descriptor[hash_idx].hashsize)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
if ((err = hash_descriptor[hash_idx].process(md, password, password_len)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = hash_descriptor[hash_idx].process(md, salt, 8)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
iter = iteration_count;
|
||||
while (--iter) {
|
||||
/* code goes here. */
|
||||
x = MAXBLOCKSIZE;
|
||||
if ((err = hash_memory(hash_idx, buf, hash_descriptor[hash_idx].hashsize, buf, &x)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* limit the size of the copy to however many bytes we have left in
|
||||
the output buffer (and how many bytes we have to copy) */
|
||||
outidx = block*hash_descriptor[hash_idx].hashsize;
|
||||
nb = hash_descriptor[hash_idx].hashsize;
|
||||
if(outidx+nb > *outlen)
|
||||
nb = *outlen - outidx;
|
||||
if(nb > 0)
|
||||
XMEMCPY(out+outidx, buf, nb);
|
||||
|
||||
block++;
|
||||
if (!openssl_compat)
|
||||
break;
|
||||
}
|
||||
/* In strict mode, we always return the hashsize, in compat we filled it
|
||||
as much as was requested, so we leave it alone. */
|
||||
if(!openssl_compat)
|
||||
*outlen = hash_descriptor[hash_idx].hashsize;
|
||||
|
||||
err = CRYPT_OK;
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(buf, MAXBLOCKSIZE);
|
||||
zeromem(md, sizeof(hash_state));
|
||||
#endif
|
||||
|
||||
XFREE(buf);
|
||||
XFREE(md);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
Execute PKCS #5 v1 - Strict mode (no OpenSSL-compatible extension)
|
||||
@param password The password (or key)
|
||||
@param password_len The length of the password (octet)
|
||||
@param salt The salt (or nonce) which is 8 octets long
|
||||
@param iteration_count The PKCS #5 v1 iteration count
|
||||
@param hash_idx The index of the hash desired
|
||||
@param out [out] The destination for this algorithm
|
||||
@param outlen [in/out] The max size and resulting size of the algorithm output
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
|
||||
const unsigned char *salt,
|
||||
int iteration_count, int hash_idx,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _pkcs_5_alg1_common(password, password_len, salt, iteration_count,
|
||||
hash_idx, out, outlen, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Execute PKCS #5 v1 - OpenSSL-extension-compatible mode
|
||||
|
||||
Use this one if you need to derive keys as "openssl enc" does by default.
|
||||
OpenSSL (for better or worse), uses MD5 as the hash and iteration_count=1.
|
||||
@param password The password (or key)
|
||||
@param password_len The length of the password (octet)
|
||||
@param salt The salt (or nonce) which is 8 octets long
|
||||
@param iteration_count The PKCS #5 v1 iteration count
|
||||
@param hash_idx The index of the hash desired
|
||||
@param out [out] The destination for this algorithm
|
||||
@param outlen [in/out] The max size and resulting size of the algorithm output
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int pkcs_5_alg1_openssl(const unsigned char *password,
|
||||
unsigned long password_len,
|
||||
const unsigned char *salt,
|
||||
int iteration_count, int hash_idx,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
return _pkcs_5_alg1_common(password, password_len, salt, iteration_count,
|
||||
hash_idx, out, outlen, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
127
thirdparty/libtomcrypt/misc/pkcs5/pkcs_5_2.c
vendored
Normal file
127
thirdparty/libtomcrypt/misc/pkcs5/pkcs_5_2.c
vendored
Normal file
@ -0,0 +1,127 @@
|
||||
/* 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 pkcs_5_2.c
|
||||
PKCS #5, Algorithm #2, Tom St Denis
|
||||
*/
|
||||
#ifdef LTC_PKCS_5
|
||||
|
||||
/**
|
||||
Execute PKCS #5 v2
|
||||
@param password The input password (or key)
|
||||
@param password_len The length of the password (octets)
|
||||
@param salt The salt (or nonce)
|
||||
@param salt_len The length of the salt (octets)
|
||||
@param iteration_count # of iterations desired for PKCS #5 v2 [read specs for more]
|
||||
@param hash_idx The index of the hash desired
|
||||
@param out [out] The destination for this algorithm
|
||||
@param outlen [in/out] The max size and resulting size of the algorithm output
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
|
||||
const unsigned char *salt, unsigned long salt_len,
|
||||
int iteration_count, int hash_idx,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
int err, itts;
|
||||
ulong32 blkno;
|
||||
unsigned long stored, left, x, y;
|
||||
unsigned char *buf[2];
|
||||
hmac_state *hmac;
|
||||
|
||||
LTC_ARGCHK(password != NULL);
|
||||
LTC_ARGCHK(salt != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* test hash IDX */
|
||||
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
buf[0] = XMALLOC(MAXBLOCKSIZE * 2);
|
||||
hmac = XMALLOC(sizeof(hmac_state));
|
||||
if (hmac == NULL || buf[0] == NULL) {
|
||||
if (hmac != NULL) {
|
||||
XFREE(hmac);
|
||||
}
|
||||
if (buf[0] != NULL) {
|
||||
XFREE(buf[0]);
|
||||
}
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
/* buf[1] points to the second block of MAXBLOCKSIZE bytes */
|
||||
buf[1] = buf[0] + MAXBLOCKSIZE;
|
||||
|
||||
left = *outlen;
|
||||
blkno = 1;
|
||||
stored = 0;
|
||||
while (left != 0) {
|
||||
/* process block number blkno */
|
||||
zeromem(buf[0], MAXBLOCKSIZE*2);
|
||||
|
||||
/* store current block number and increment for next pass */
|
||||
STORE32H(blkno, buf[1]);
|
||||
++blkno;
|
||||
|
||||
/* get PRF(P, S||int(blkno)) */
|
||||
if ((err = hmac_init(hmac, hash_idx, password, password_len)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = hmac_process(hmac, salt, salt_len)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = hmac_process(hmac, buf[1], 4)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
x = MAXBLOCKSIZE;
|
||||
if ((err = hmac_done(hmac, buf[0], &x)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* now compute repeated and XOR it in buf[1] */
|
||||
XMEMCPY(buf[1], buf[0], x);
|
||||
for (itts = 1; itts < iteration_count; ++itts) {
|
||||
if ((err = hmac_memory(hash_idx, password, password_len, buf[0], x, buf[0], &x)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
for (y = 0; y < x; y++) {
|
||||
buf[1][y] ^= buf[0][y];
|
||||
}
|
||||
}
|
||||
|
||||
/* now emit upto x bytes of buf[1] to output */
|
||||
for (y = 0; y < x && left != 0; ++y) {
|
||||
out[stored++] = buf[1][y];
|
||||
--left;
|
||||
}
|
||||
}
|
||||
*outlen = stored;
|
||||
|
||||
err = CRYPT_OK;
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(buf[0], MAXBLOCKSIZE*2);
|
||||
zeromem(hmac, sizeof(hmac_state));
|
||||
#endif
|
||||
|
||||
XFREE(hmac);
|
||||
XFREE(buf[0]);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
231
thirdparty/libtomcrypt/misc/pkcs5/pkcs_5_test.c
vendored
Normal file
231
thirdparty/libtomcrypt/misc/pkcs5/pkcs_5_test.c
vendored
Normal file
@ -0,0 +1,231 @@
|
||||
/* 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 hkdf_test.c
|
||||
PKCS #5 support, self-test, Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#ifdef LTC_PKCS_5
|
||||
|
||||
/*
|
||||
TEST CASES SOURCE:
|
||||
|
||||
Internet Engineering Task Force (IETF) S. Josefsson
|
||||
Request for Comments: 6070 SJD AB
|
||||
Category: Informational January 2011
|
||||
ISSN: 2070-1721
|
||||
*/
|
||||
|
||||
/**
|
||||
PKCS #5 self-test
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled.
|
||||
*/
|
||||
int pkcs_5_test (void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
|
||||
typedef struct {
|
||||
const char* P;
|
||||
unsigned long P_len;
|
||||
const char* S;
|
||||
unsigned long S_len;
|
||||
int c;
|
||||
unsigned long dkLen;
|
||||
unsigned char DK[40];
|
||||
} case_item;
|
||||
|
||||
static const case_item cases_5_2[] = {
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"salt",
|
||||
4,
|
||||
1,
|
||||
20,
|
||||
{ 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
|
||||
0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
|
||||
0x2f, 0xe0, 0x37, 0xa6 }
|
||||
},
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"salt",
|
||||
4,
|
||||
2,
|
||||
20,
|
||||
{ 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c,
|
||||
0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
|
||||
0xd8, 0xde, 0x89, 0x57 }
|
||||
},
|
||||
#ifdef LTC_TEST_EXT
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"salt",
|
||||
4,
|
||||
4096,
|
||||
20,
|
||||
{ 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
|
||||
0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
|
||||
0x65, 0xa4, 0x29, 0xc1 }
|
||||
},
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"salt",
|
||||
4,
|
||||
16777216,
|
||||
20,
|
||||
{ 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4,
|
||||
0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c,
|
||||
0x26, 0x34, 0xe9, 0x84 }
|
||||
},
|
||||
{
|
||||
"passwordPASSWORDpassword",
|
||||
25,
|
||||
"saltSALTsaltSALTsaltSALTsaltSALTsalt",
|
||||
36,
|
||||
4096,
|
||||
25,
|
||||
{ 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
|
||||
0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
|
||||
0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
|
||||
0x38 }
|
||||
},
|
||||
{
|
||||
"pass\0word",
|
||||
9,
|
||||
"sa\0lt",
|
||||
5,
|
||||
4096,
|
||||
16,
|
||||
{ 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
|
||||
0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 }
|
||||
},
|
||||
#endif /* LTC_TEST_EXT */
|
||||
};
|
||||
|
||||
static const case_item cases_5_1[] = {
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"saltsalt", /* must be 8 octects */
|
||||
8, /* ignored by alg1 */
|
||||
1,
|
||||
20,
|
||||
{ 0xca, 0xb8, 0x6d, 0xd6, 0x26, 0x17, 0x10, 0x89, 0x1e, 0x8c,
|
||||
0xb5, 0x6e, 0xe3, 0x62, 0x56, 0x91, 0xa7, 0x5d, 0xf3, 0x44 }
|
||||
},
|
||||
};
|
||||
|
||||
static const case_item cases_5_1o[] = {
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"saltsalt", /* must be 8 octects */
|
||||
8, /* ignored by alg1_openssl */
|
||||
1,
|
||||
20,
|
||||
{ 0xca, 0xb8, 0x6d, 0xd6, 0x26, 0x17, 0x10, 0x89, 0x1e, 0x8c,
|
||||
0xb5, 0x6e, 0xe3, 0x62, 0x56, 0x91, 0xa7, 0x5d, 0xf3, 0x44 }
|
||||
|
||||
},
|
||||
{
|
||||
"password",
|
||||
8,
|
||||
"saltsalt", /* must be 8 octects */
|
||||
8, /* ignored by alg1_openssl */
|
||||
1,
|
||||
30,
|
||||
{ 0xca, 0xb8, 0x6d, 0xd6, 0x26, 0x17, 0x10, 0x89, 0x1e, 0x8c,
|
||||
0xb5, 0x6e, 0xe3, 0x62, 0x56, 0x91, 0xa7, 0x5d, 0xf3, 0x44,
|
||||
0xf0, 0xbf, 0xf4, 0xc1, 0x2c, 0xf3, 0x59, 0x6f, 0xc0, 0x0b }
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
unsigned char DK[40];
|
||||
unsigned long dkLen;
|
||||
int i, err;
|
||||
int tested=0, failed=0;
|
||||
int hash = find_hash("sha1");
|
||||
if (hash == -1)
|
||||
{
|
||||
#ifdef LTC_TEST_DBG
|
||||
printf("PKCS#5 test failed: 'sha1' hash not found\n");
|
||||
#endif
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
/* testing alg 2 */
|
||||
for(i=0; i < (int)(sizeof(cases_5_2) / sizeof(cases_5_2[0])); i++) {
|
||||
++tested;
|
||||
dkLen = cases_5_2[i].dkLen;
|
||||
if((err = pkcs_5_alg2((unsigned char*)cases_5_2[i].P, cases_5_2[i].P_len,
|
||||
(unsigned char*)cases_5_2[i].S, cases_5_2[i].S_len,
|
||||
cases_5_2[i].c, hash,
|
||||
DK, &dkLen)) != CRYPT_OK) {
|
||||
#ifdef LTC_TEST_DBG
|
||||
printf("\npkcs_5_alg2() #%d: Failed/1 (%s)\n", i, error_to_string(err));
|
||||
#endif
|
||||
++failed;
|
||||
}
|
||||
else if (compare_testvector(DK, dkLen, cases_5_2[i].DK, cases_5_2[i].dkLen, "PKCS#5_2", i)) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
/* testing alg 1 */
|
||||
for(i=0; i < (int)(sizeof(cases_5_1) / sizeof(case_item)); i++, tested++) {
|
||||
dkLen = cases_5_1[i].dkLen;
|
||||
if((err = pkcs_5_alg1((unsigned char*)cases_5_1[i].P, cases_5_1[i].P_len,
|
||||
(unsigned char*)cases_5_1[i].S,
|
||||
cases_5_1[i].c, hash,
|
||||
DK, &dkLen)) != CRYPT_OK) {
|
||||
#ifdef LTC_TEST_DBG
|
||||
printf("\npkcs_5_alg1() #%d: Failed/1 (%s)\n", i, error_to_string(err));
|
||||
#endif
|
||||
++failed;
|
||||
}
|
||||
else if (compare_testvector(DK, dkLen, cases_5_1[i].DK, cases_5_1[i].dkLen, "PKCS#5_1", i)) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
/* testing alg 1_openssl */
|
||||
for(i = 0; i < (int)(sizeof(cases_5_1o) / sizeof(cases_5_1o[0])); i++, tested++) {
|
||||
dkLen = cases_5_1o[i].dkLen;
|
||||
if ((err = pkcs_5_alg1_openssl((unsigned char*)cases_5_1o[i].P, cases_5_1o[i].P_len,
|
||||
(unsigned char*)cases_5_1o[i].S,
|
||||
cases_5_1o[i].c, hash,
|
||||
DK, &dkLen)) != CRYPT_OK) {
|
||||
#ifdef LTC_TEST_DBG
|
||||
printf("\npkcs_5_alg1_openssl() #%d: Failed/1 (%s)\n", i, error_to_string(err));
|
||||
#endif
|
||||
++failed;
|
||||
}
|
||||
else if (compare_testvector(DK, dkLen, cases_5_1o[i].DK, cases_5_1o[i].dkLen, "PKCS#5_1o", i)) {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
return (failed != 0) ? CRYPT_FAIL_TESTVECTOR : CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
32
thirdparty/libtomcrypt/misc/zeromem.c
vendored
Normal file
32
thirdparty/libtomcrypt/misc/zeromem.c
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/* 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 zeromem.c
|
||||
Zero a block of memory, Tom St Denis
|
||||
*/
|
||||
|
||||
/**
|
||||
Zero a block of memory
|
||||
@param out The destination of the area to zero
|
||||
@param outlen The length of the area to zero (octets)
|
||||
*/
|
||||
void zeromem(volatile void *out, size_t outlen)
|
||||
{
|
||||
volatile char *mem = out;
|
||||
LTC_ARGCHKVD(out != NULL);
|
||||
while (outlen-- > 0) {
|
||||
*mem++ = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* 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