CRYPTO-C v1.1.3
C/C++ Documentation
sha3.h File Reference

Go to the source code of this file.

#include "utildev.h"

Detailed Description

SHA3 hash function support.

This file is based on Dr. Markku-Juhani O. Saarinen's "cooked up" compact and readable keccak implemetation...

https://github.com/mjosaarinen/tiny_sha3

... which was released under the MIT license (MIT).

Alterations to the transform function were based on Marko Kreen's optimized C implementation...

https://github.com/markokr/spongeshaker

... which was released under the ISC License (ISC).

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

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, subject to the following conditions:

  • The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macros

#define SHA3LEN224   28
 SHA3 224-bit digest length, in bytes.
 
#define SHA3LEN256   32
 SHA3 256-bit digest length, in bytes.
 
#define SHA3LEN384   48
 SHA3 384-bit digest length, in bytes.
 
#define SHA3LEN512   64
 SHA3 512-bit digest length, in bytes.
 
#define KECCAKLEN224   28
 KECCAK 224-bit digest length, in bytes.
 
#define KECCAKLEN256   32
 KECCAK 256-bit digest length, in bytes.
 
#define KECCAKLEN384   48
 KECCAK 384-bit digest length, in bytes.
 
#define KECCAKLEN512   64
 KECCAK 512-bit digest length, in bytes.
 

Data Structures

struct  SHA3_KECCAK_CTX
 SHA3/Keccak hashing context. More...
 

Functions

void sha3_init (SHA3_KECCAK_CTX *ctx, int outlen)
 Initialize a SHA3 context. More...
 
void sha3_update (SHA3_KECCAK_CTX *ctx, const void *in, size_t inlen)
 Add inlen bytes from in to a SHA3 context for hashing. More...
 
void sha3_final (SHA3_KECCAK_CTX *ctx, void *out)
 Finalize a SHA3 message digest. More...
 
void sha3 (const void *in, size_t inlen, void *out, int outlen)
 Convenient all-in-one SHA3 computation. More...
 
void keccak_init (SHA3_KECCAK_CTX *ctx, int outlen)
 Initialize a Keccak context. More...
 
void keccak_update (SHA3_KECCAK_CTX *ctx, const void *in, size_t inlen)
 Add inlen bytes from in to a Keccak context for hashing. More...
 
void keccak_final (SHA3_KECCAK_CTX *ctx, void *out)
 Finalize a Keccak message digest. More...
 
void keccak (const void *in, size_t inlen, void *out, int outlen)
 Convenient all-in-one Keccak computation. More...
 

Function Documentation

◆ keccak()

void keccak ( const void *  in,
size_t  inlen,
void *  out,
int  outlen 
)

Convenient all-in-one Keccak computation.

Performs keccak_init(), keccak_update() and keccak_final(), and places the resulting hash in out.

Parameters
inPointer to data to hash
inlenLength of in data, in bytes
outPointer to location to place the message digest
outlenLength* of desired message digest, in bytes
*compatible message digest lengths are 28, 32, 48 and 64

◆ keccak_final()

void keccak_final ( SHA3_KECCAK_CTX ctx,
void *  out 
)

Finalize a Keccak message digest.

Generate the Keccak message digest and place in out.

Parameters
ctxPointer to Keccak context
outPointer to location to place the message digest

◆ keccak_init()

void keccak_init ( SHA3_KECCAK_CTX ctx,
int  outlen 
)

Initialize a Keccak context.

Parameters
ctxPointer to Keccak context
outlenLength* of desired message digest, in bytes
*compatible message digest lengths are 28, 32, 48 and 64

◆ keccak_update()

void keccak_update ( SHA3_KECCAK_CTX ctx,
const void *  in,
size_t  inlen 
)

Add inlen bytes from in to a Keccak context for hashing.

Parameters
ctxPointer to Keccak context
inPointer to data to hash
inlenLength of in data, in bytes

◆ sha3()

void sha3 ( const void *  in,
size_t  inlen,
void *  out,
int  outlen 
)

Convenient all-in-one SHA3 computation.

Performs sha3_init(), sha3_update() and sha3_final(), and places the resulting hash in out.

Parameters
inPointer to data to hash
inlenLength of in data, in bytes
outPointer to location to place the message digest
outlenLength* of desired message digest, in bytes
*compatible message digest lengths are 28, 32, 48 and 64

◆ sha3_final()

void sha3_final ( SHA3_KECCAK_CTX ctx,
void *  out 
)

Finalize a SHA3 message digest.

Generate the SHA3 message digest and place in out.

Parameters
ctxPointer to SHA3 context
outPointer to location to place the message digest

◆ sha3_init()

void sha3_init ( SHA3_KECCAK_CTX ctx,
int  outlen 
)

Initialize a SHA3 context.

Parameters
ctxPointer to SHA3 context
outlenLength* of desired message digest, in bytes
*compatible message digest lengths are 28, 32, 48 and 64

◆ sha3_update()

void sha3_update ( SHA3_KECCAK_CTX ctx,
const void *  in,
size_t  inlen 
)

Add inlen bytes from in to a SHA3 context for hashing.

Parameters
ctxPointer to SHA3 context
inPointer to data to hash
inlenLength of in data, in bytes