/*
* IDI,NTNU
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright (C) 2009, 2010, Jorn Amundsen <jorn.amundsen@ntnu.no>
* Tweaked Edon-R implementation for SUPERCOP, based on NIST API.
*
*/
/*
* Portions copyright (c) 2013, Saso Kiselkov, All rights reserved
* Copyright 2016 Gary Mills
*/
#ifdef _KERNEL
#else
#include <strings.h>
#endif
/* big endian support, provides no-op's if run on little endian hosts */
#include "edonr_byteorder.h"
/* shift and rotate shortcuts */
#define shl(x, n) ((x) << n)
#define shr(x, n) ((x) >> n)
#if !defined(__C99_RESTRICT)
#define restrict /* restrict */
#endif
#define EDONR_VALID_HASHBITLEN(x) \
((x) == 512 || (x) == 384 || (x) == 256 || (x) == 224)
/* EdonR224 initial double chaining pipe */
0x00010203ul, 0x04050607ul, 0x08090a0bul, 0x0c0d0e0ful,
0x10111213ul, 0x14151617ul, 0x18191a1bul, 0x1c1d1e1ful,
0x20212223ul, 0x24252627ul, 0x28292a2bul, 0x2c2d2e2ful,
0x30313233ul, 0x34353637ul, 0x38393a3bul, 0x3c3d3e3ful,
};
/* EdonR256 initial double chaining pipe */
0x40414243ul, 0x44454647ul, 0x48494a4bul, 0x4c4d4e4ful,
0x50515253ul, 0x54555657ul, 0x58595a5bul, 0x5c5d5e5ful,
0x60616263ul, 0x64656667ul, 0x68696a6bul, 0x6c6d6e6ful,
0x70717273ul, 0x74757677ul, 0x78797a7bul, 0x7c7d7e7ful,
};
/* EdonR384 initial double chaining pipe */
0x0001020304050607ull, 0x08090a0b0c0d0e0full,
0x1011121314151617ull, 0x18191a1b1c1d1e1full,
0x2021222324252627ull, 0x28292a2b2c2d2e2full,
0x3031323334353637ull, 0x38393a3b3c3d3e3full,
0x4041424344454647ull, 0x48494a4b4c4d4e4full,
0x5051525354555657ull, 0x58595a5b5c5d5e5full,
0x6061626364656667ull, 0x68696a6b6c6d6e6full,
0x7071727374757677ull, 0x78797a7b7c7d7e7full
};
/* EdonR512 initial double chaining pipe */
0x8081828384858687ull, 0x88898a8b8c8d8e8full,
0x9091929394959697ull, 0x98999a9b9c9d9e9full,
0xa0a1a2a3a4a5a6a7ull, 0xa8a9aaabacadaeafull,
0xb0b1b2b3b4b5b6b7ull, 0xb8b9babbbcbdbebfull,
0xc0c1c2c3c4c5c6c7ull, 0xc8c9cacbcccdcecfull,
0xd0d1d2d3d4d5d6d7ull, 0xd8d9dadbdcdddedfull,
0xe0e1e2e3e4e5e6e7ull, 0xe8e9eaebecedeeefull,
0xf0f1f2f3f4f5f6f7ull, 0xf8f9fafbfcfdfeffull
};
/*
* First Latin Square
* 0 7 1 3 2 4 6 5
* 4 1 7 6 3 0 5 2
* 7 0 4 2 5 3 1 6
* 1 4 0 5 6 2 7 3
* 2 3 6 7 1 5 0 4
* 5 2 3 1 7 6 4 0
* 3 6 5 0 4 7 2 1
* 6 5 2 4 0 1 3 7
*/
{ \
}
{ \
}
/*
* Second Orthogonal Latin Square
* 0 4 2 3 1 6 5 7
* 7 6 3 2 5 4 1 0
* 5 3 1 6 0 2 7 4
* 1 0 5 4 3 7 2 6
* 2 1 0 7 4 5 6 3
* 3 5 7 0 6 1 4 2
* 4 7 6 1 2 0 3 5
* 6 2 4 5 7 3 0 1
*/
{ \
}
{ \
}
{ \
}
{ \
}
static size_t
{
#if defined(MACHINE_IS_BIG_ENDIAN)
#define d(j) swp ## j
#else
#define d(j) data[j]
#endif
/* First row of quasigroup e-transformations */
#if defined(MACHINE_IS_BIG_ENDIAN)
s32(8);
s32(9);
s32(10);
s32(11);
s32(12);
s32(13);
s32(14);
s32(15);
#endif
d(8));
#if defined(MACHINE_IS_BIG_ENDIAN)
s32(0);
s32(1);
s32(2);
s32(3);
s32(4);
s32(5);
s32(6);
s32(7);
#endif
d(15));
/* Second row of quasigroup e-transformations */
p[15]);
/* Third row of quasigroup e-transformations */
/* Fourth row of quasigroup e-transformations */
/* Edon-R tweak on the original SHA-3 Edon-R submission. */
p[0] ^= d(8) ^ p0;
p[8] ^= d(0) ^ q0;
}
#undef d
}
static inline size_t
#else
static size_t
#endif
{
#if defined(MACHINE_IS_BIG_ENDIAN)
#define d(j) swp##j
#else
#define d(j) data[j]
#endif
/* First row of quasigroup e-transformations */
#if defined(MACHINE_IS_BIG_ENDIAN)
s64(8);
s64(9);
s64(10);
s64(11);
s64(12);
s64(13);
s64(14);
s64(15);
#endif
d(8));
#if defined(MACHINE_IS_BIG_ENDIAN)
s64(0);
s64(1);
s64(2);
s64(3);
s64(4);
s64(5);
s64(6);
s64(7);
#endif
d(15));
/* Second row of quasigroup e-transformations */
p[15]);
/* Third row of quasigroup e-transformations */
/* Fourth row of quasigroup e-transformations */
/* Edon-R tweak on the original SHA-3 Edon-R submission. */
p[0] ^= d(8) ^ p0;
p[8] ^= d(0) ^ q0;
}
#undef d
}
void
{
switch (hashbitlen) {
case 224:
state->bits_processed = 0;
state->unprocessed_bits = 0;
16 * sizeof (uint32_t));
break;
case 256:
state->bits_processed = 0;
state->unprocessed_bits = 0;
16 * sizeof (uint32_t));
break;
case 384:
state->bits_processed = 0;
state->unprocessed_bits = 0;
16 * sizeof (uint64_t));
break;
case 512:
state->bits_processed = 0;
state->unprocessed_bits = 0;
16 * sizeof (uint64_t));
break;
}
}
void
{
switch (state->hashbitlen) {
case 224:
case 256:
if (state->unprocessed_bits > 0) {
/* LastBytes = databitlen / 8 */
EdonR256_BLOCK_SIZE * 8);
/* LINTED E_BAD_PTR_CAST_ALIGN */
} else
/* LINTED E_BAD_PTR_CAST_ALIGN */
if (databitlen > 0) {
/* LastBytes = Ceil(databitlen / 8) */
int LastBytes =
1) & 0x01ff;
}
break;
case 384:
case 512:
if (state->unprocessed_bits > 0) {
/* LastBytes = databitlen / 8 */
EdonR512_BLOCK_SIZE * 8);
/* LINTED E_BAD_PTR_CAST_ALIGN */
} else
/* LINTED E_BAD_PTR_CAST_ALIGN */
if (databitlen > 0) {
/* LastBytes = Ceil(databitlen / 8) */
int LastBytes =
1) & 0x03ff;
}
break;
}
}
void
{
switch (state->hashbitlen) {
case 224:
case 256:
(0x01 << PadOnePosition);
/* LINTED E_BAD_PTR_CAST_ALIGN */
#if defined(MACHINE_IS_BIG_ENDIAN)
#else
#endif
} else {
#if defined(MACHINE_IS_BIG_ENDIAN)
#else
#endif
}
/* LINTED E_BAD_PTR_CAST_ALIGN */
break;
case 384:
case 512:
(0x01 << PadOnePosition);
/* LINTED E_BAD_PTR_CAST_ALIGN */
#if defined(MACHINE_IS_BIG_ENDIAN)
#else
#endif
} else {
#if defined(MACHINE_IS_BIG_ENDIAN)
#else
#endif
}
break;
}
switch (state->hashbitlen) {
case 224: {
#if defined(MACHINE_IS_BIG_ENDIAN)
/* LINTED: pointer cast may result in improper alignment */
int j;
for (j = 0; j < EdonR224_DIGEST_SIZE >> 2; j++)
#else
#endif
break;
}
case 256: {
#if defined(MACHINE_IS_BIG_ENDIAN)
/* LINTED: pointer cast may result in improper alignment */
int j;
for (j = 0; j < EdonR256_DIGEST_SIZE >> 2; j++)
#else
#endif
break;
}
case 384: {
#if defined(MACHINE_IS_BIG_ENDIAN)
/* LINTED: pointer cast may result in improper alignment */
int j;
for (j = 0; j < EdonR384_DIGEST_SIZE >> 3; j++)
#else
#endif
break;
}
case 512: {
#if defined(MACHINE_IS_BIG_ENDIAN)
/* LINTED: pointer cast may result in improper alignment */
int j;
for (j = 0; j < EdonR512_DIGEST_SIZE >> 3; j++)
#else
#endif
break;
}
}
}
void
{
}