mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-31 09:50:58 +00:00
74 lines
2.4 KiB
C
74 lines
2.4 KiB
C
|
/* sha3.h - an implementation of Secure Hash Algorithm 3 (Keccak).
|
||
|
* based on the
|
||
|
* The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
|
||
|
* by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche
|
||
|
*
|
||
|
* Copyright: 2013 Aleksey Kravchenko <rhash.admin@gmail.com>
|
||
|
*
|
||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
* copy of this software and associated documentation files (the "Software"),
|
||
|
* to deal in the Software without restriction, including without limitation
|
||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||
|
* Software is furnished to do so.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but
|
||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
|
* or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
|
||
|
*/
|
||
|
|
||
|
#ifndef RHASH_SHA3_H
|
||
|
#define RHASH_SHA3_H
|
||
|
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
#define sha3_224_hash_size 28
|
||
|
#define sha3_256_hash_size 32
|
||
|
#define sha3_384_hash_size 48
|
||
|
#define sha3_512_hash_size 64
|
||
|
#define sha3_max_permutation_size 25
|
||
|
#define sha3_max_rate_in_qwords 24
|
||
|
|
||
|
/**
|
||
|
* SHA3 Algorithm context.
|
||
|
*/
|
||
|
typedef struct sha3_ctx
|
||
|
{
|
||
|
/* 1600 bits algorithm hashing state */
|
||
|
uint64_t hash[sha3_max_permutation_size];
|
||
|
/* 1536-bit buffer for leftovers */
|
||
|
uint64_t message[sha3_max_rate_in_qwords];
|
||
|
/* count of bytes in the message[] buffer */
|
||
|
unsigned rest;
|
||
|
/* size of a message block processed at once */
|
||
|
unsigned block_size;
|
||
|
} sha3_ctx;
|
||
|
|
||
|
/* methods for calculating the hash function */
|
||
|
|
||
|
void rhash_sha3_224_init(sha3_ctx *ctx);
|
||
|
void rhash_sha3_256_init(sha3_ctx *ctx);
|
||
|
void rhash_sha3_384_init(sha3_ctx *ctx);
|
||
|
void rhash_sha3_512_init(sha3_ctx *ctx);
|
||
|
void rhash_sha3_update(sha3_ctx *ctx, const unsigned char* msg, size_t size);
|
||
|
void rhash_sha3_final(sha3_ctx *ctx, unsigned char* result);
|
||
|
|
||
|
#ifdef USE_KECCAK
|
||
|
#define rhash_keccak_224_init rhash_sha3_224_init
|
||
|
#define rhash_keccak_256_init rhash_sha3_256_init
|
||
|
#define rhash_keccak_384_init rhash_sha3_384_init
|
||
|
#define rhash_keccak_512_init rhash_sha3_512_init
|
||
|
#define rhash_keccak_update rhash_sha3_update
|
||
|
void rhash_keccak_final(sha3_ctx *ctx, unsigned char* result);
|
||
|
#endif
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
} /* extern "C" */
|
||
|
#endif /* __cplusplus */
|
||
|
|
||
|
#endif /* RHASH_SHA3_H */
|