Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Apr 24, 2024
1 parent 7fa0f36 commit ab4c8f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
5 changes: 4 additions & 1 deletion R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ shake256 <- function(x, bits = 256L, convert = TRUE, file)
#' @return A character string, raw or integer vector depending on 'convert'.
#'
#' @details Keccak is the underlying algorithm for SHA-3, and is identical apart
#' from the padding value.
#' from the value of the padding parameter.
#'
#' The Keccak algorithm was designed by G. Bertoni, J. Daemen, M. Peeters
#' and G. Van Assche.
#'
#' This implementation is based on one by 'The Mbed TLS Contributors' under
#' the 'Mbed TLS' Trusted Firmware Project at
Expand Down
5 changes: 4 additions & 1 deletion man/keccak.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@
* https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf
*/

typedef enum {
MBEDTLS_SHA3_SHAKE256 = 0,
MBEDTLS_SHA3_224,
MBEDTLS_SHA3_256,
MBEDTLS_SHA3_384,
MBEDTLS_SHA3_512,
MBEDTLS_KECCAK_224,
MBEDTLS_KECCAK_256,
MBEDTLS_KECCAK_384,
MBEDTLS_KECCAK_512,
} mbedtls_sha3_id;

typedef struct mbedtls_sha3_family_functions {
mbedtls_sha3_id id;
uint16_t r;
uint16_t olen;
uint8_t xor_byte;
} mbedtls_sha3_family_functions;

static mbedtls_sha3_family_functions sha3_families[] = {
{ MBEDTLS_SHA3_SHAKE256, 1088, 0, 0x1F },
{ MBEDTLS_SHA3_224, 1152, 224, 0x06 },
Expand Down
31 changes: 5 additions & 26 deletions src/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,6 @@
#define SB_SIPH_SIZE 8
#define SB_SKEY_SIZE 16

typedef enum {
MBEDTLS_SHA3_SHAKE256 = 0,
MBEDTLS_SHA3_224,
MBEDTLS_SHA3_256,
MBEDTLS_SHA3_384,
MBEDTLS_SHA3_512,
MBEDTLS_KECCAK_224,
MBEDTLS_KECCAK_256,
MBEDTLS_KECCAK_384,
MBEDTLS_KECCAK_512,
} mbedtls_sha3_id;

typedef struct mbedtls_sha3_family_functions {
mbedtls_sha3_id id;
uint16_t r;
uint16_t olen;
uint8_t xor_byte;
} mbedtls_sha3_family_functions;

typedef struct mbedtls_sha3_context {
uint64_t state[25];
uint8_t index;
Expand All @@ -76,11 +57,6 @@ typedef struct mbedtls_sha256_context {
uint32_t state[8];
} mbedtls_sha256_context;

typedef struct secretbase_sha3_context {
int skip;
mbedtls_sha3_context *ctx;
} secretbase_sha3_context;

typedef struct CSipHash {
uint64_t v0;
uint64_t v1;
Expand All @@ -90,6 +66,11 @@ typedef struct CSipHash {
size_t n_bytes;
} CSipHash;

typedef struct secretbase_sha3_context {
int skip;
mbedtls_sha3_context *ctx;
} secretbase_sha3_context;

typedef struct secretbase_sha256_context {
int skip;
mbedtls_sha256_context *ctx;
Expand All @@ -113,7 +94,5 @@ SEXP secretbase_sha256(SEXP, SEXP, SEXP);
SEXP secretbase_sha256_file(SEXP, SEXP, SEXP);
SEXP secretbase_siphash13(SEXP, SEXP, SEXP);
SEXP secretbase_siphash13_file(SEXP, SEXP, SEXP);
SEXP secretbase_siphash24(SEXP, SEXP, SEXP);
SEXP secretbase_siphash24_file(SEXP, SEXP, SEXP);

#endif

0 comments on commit ab4c8f1

Please sign in to comment.