XRootD
XrdOucSHA3 Class Reference

#include <XrdOucSHA3.hh>

+ Collaboration diagram for XrdOucSHA3:

Classes

struct  sha3_ctx_t
 SHA3 state context used by all methods (OpenSSL - like interface) More...
 
union  sha3_ctx_t.st
 

Public Types

enum  MDLen {
  SHA3_128 = 16 ,
  SHA3_224 = 28 ,
  SHA3_256 = 32 ,
  SHA3_384 = 48 ,
  SHA3_512 = 64
}
 SHA3 digest lengths (bits to bytes). More...
 

Public Member Functions

 XrdOucSHA3 ()
 
 ~XrdOucSHA3 ()
 

Static Public Member Functions

static void * Calc (const void *in, size_t inlen, void *md, MDLen mdlen)
 
static void Final (sha3_ctx_t *c, void *md)
 
static void Init (sha3_ctx_t *c, MDLen mdlen)
 
static void SHAKE128_Init (sha3_ctx_t *c)
 
static void SHAKE256_Init (sha3_ctx_t *c)
 
static void SHAKE_Out (sha3_ctx_t *c, void *out, size_t len)
 
static void SHAKE_Update (sha3_ctx_t *c, const void *data, size_t len)
 
static void Update (sha3_ctx_t *c, const void *data, size_t len)
 

Detailed Description

Definition at line 36 of file XrdOucSHA3.hh.


Class Documentation

◆ XrdOucSHA3::sha3_ctx_t

struct XrdOucSHA3::sha3_ctx_t

SHA3 state context used by all methods (OpenSSL - like interface)

Definition at line 44 of file XrdOucSHA3.hh.

+ Collaboration diagram for XrdOucSHA3::sha3_ctx_t:
Class Members
int mdlen
int pt
int rsiz
union sha3_ctx_t st
int xof these don't overflow

◆ XrdOucSHA3::sha3_ctx_t.st

union XrdOucSHA3::sha3_ctx_t.st

Definition at line 45 of file XrdOucSHA3.hh.

+ Collaboration diagram for XrdOucSHA3::sha3_ctx_t.st:
Class Members
uint8_t b[200] < state:

8-bit bytes

uint64_t q[25] 64-bit words

Member Enumeration Documentation

◆ MDLen

SHA3 digest lengths (bits to bytes).

Enumerator
SHA3_128 
SHA3_224 
SHA3_256 
SHA3_384 
SHA3_512 

Definition at line 56 of file XrdOucSHA3.hh.

56  {SHA3_128 = 16,
57  SHA3_224 = 28,
58  SHA3_256 = 32,
59  SHA3_384 = 48,
60  SHA3_512 = 64
61  };

Constructor & Destructor Documentation

◆ XrdOucSHA3()

XrdOucSHA3::XrdOucSHA3 ( )
inline

Definition at line 143 of file XrdOucSHA3.hh.

143 {}

◆ ~XrdOucSHA3()

XrdOucSHA3::~XrdOucSHA3 ( )
inline

Definition at line 144 of file XrdOucSHA3.hh.

144 {}

Member Function Documentation

◆ Calc()

void * XrdOucSHA3::Calc ( const void *  in,
size_t  inlen,
void *  md,
XrdOucSHA3::MDLen  mdlen 
)
static

Compute a sha3 hash (md) of given byte length from "in" (one time call).

Parameters
inPointer to input data.
inlenLength of data in bytes.
mdPointer to mbuffer of size SHA3_xxx to receive result.
mdlenMessage digest byte length (one of the listed enums).
Returns
Pointer to md.

Definition at line 150 of file XrdOucSHA3.cc.

152 {
153  sha3_ctx_t sha3;
154 
155  Init(&sha3, mdlen);
156  Update(&sha3, in, inlen);
157  Final(&sha3, md);
158 
159  return md;
160 }
static void Update(sha3_ctx_t *c, const void *data, size_t len)
Definition: XrdOucSHA3.cc:186
static void Init(sha3_ctx_t *c, MDLen mdlen)
Definition: XrdOucSHA3.cc:168
static void Final(sha3_ctx_t *c, void *md)
Definition: XrdOucSHA3.cc:208

References Final(), Init(), and Update().

+ Here is the call graph for this function:

◆ Final()

void XrdOucSHA3::Final ( XrdOucSHA3::sha3_ctx_t c,
void *  md 
)
static

Return final message digest.

Parameters
cPointer to context.
mdPointer to buffer of size SHA3_xxx to receive result.

Definition at line 208 of file XrdOucSHA3.cc.

209 {
210  int i;
211 
212  c->st.b[c->pt] ^= 0x06;
213  c->st.b[c->rsiz - 1] ^= 0x80;
214  sha3_keccakf(c->st.q);
215 
216  for (i = 0; i < c->mdlen; i++) {
217  ((uint8_t *) md)[i] = c->st.b[i];
218  }
219 }
union XrdOucSHA3::sha3_ctx_t::@120 st

References XrdOucSHA3::sha3_ctx_t::mdlen, XrdOucSHA3::sha3_ctx_t::pt, XrdOucSHA3::sha3_ctx_t::rsiz, and XrdOucSHA3::sha3_ctx_t::st.

Referenced by Calc().

+ Here is the caller graph for this function:

◆ Init()

void XrdOucSHA3::Init ( XrdOucSHA3::sha3_ctx_t c,
XrdOucSHA3::MDLen  mdlen 
)
static

Initialize context in prepration for computing SHA3 checksum.

Parameters
cPointer to context.
mdlenMessage digest byte length (one of the listed enums).

Definition at line 168 of file XrdOucSHA3.cc.

169 {
170  int i;
171 
172  for (i = 0; i < 25; i++)
173  c->st.q[i] = 0;
174  c->mdlen = (int)mdlen;
175  c->rsiz = 200 - 2 * (int)mdlen;
176  c->pt = 0;
177  c->xof= 1;
178 }
int xof
these don't overflow
Definition: XrdOucSHA3.hh:49

References XrdOucSHA3::sha3_ctx_t::mdlen, XrdOucSHA3::sha3_ctx_t::pt, XrdOucSHA3::sha3_ctx_t::rsiz, XrdOucSHA3::sha3_ctx_t::st, and XrdOucSHA3::sha3_ctx_t::xof.

Referenced by Calc(), SHAKE128_Init(), and SHAKE256_Init().

+ Here is the caller graph for this function:

◆ SHAKE128_Init()

static void XrdOucSHA3::SHAKE128_Init ( sha3_ctx_t c)
inlinestatic

Initialize context to compute an extensible hash using a SHA3_128 digest.

Parameters
cPointer to context.

Definition at line 110 of file XrdOucSHA3.hh.

110 {Init(c, SHA3_128);}

References Init(), and SHA3_128.

+ Here is the call graph for this function:

◆ SHAKE256_Init()

static void XrdOucSHA3::SHAKE256_Init ( sha3_ctx_t c)
inlinestatic

Initialize context to compute an extensible hash using a SHA3_256 digest.

Parameters
cPointer to context.

Definition at line 118 of file XrdOucSHA3.hh.

118 {Init(c, SHA3_256);}

References Init(), and SHA3_256.

+ Here is the call graph for this function:

◆ SHAKE_Out()

void XrdOucSHA3::SHAKE_Out ( XrdOucSHA3::sha3_ctx_t c,
void *  out,
size_t  len 
)
static

Return final message digest of desired length. This function may be called iteratively to get as many bits as needed. Bits beyound MDLen form a pseudo-random sequence (i.e. are repeatable with the same input).

Parameters
cPointer to context.
outPointer to buffer of size len to receive result.
lenThe number of digest bytes to return.

Definition at line 239 of file XrdOucSHA3.cc.

240 {
241  size_t i;
242  int j;
243 
244  if (c->xof)
245  {shake_xof(c);
246  c->xof = 0;
247  }
248 
249  j = c->pt;
250  for (i = 0; i < len; i++) {
251  if (j >= c->rsiz) {
252  sha3_keccakf(c->st.q);
253  j = 0;
254  }
255  ((uint8_t *) out)[i] = c->st.b[j++];
256  }
257  c->pt = j;
258 }

References XrdOucSHA3::sha3_ctx_t::pt, XrdOucSHA3::sha3_ctx_t::rsiz, XrdOucSHA3::sha3_ctx_t::st, and XrdOucSHA3::sha3_ctx_t::xof.

◆ SHAKE_Update()

static void XrdOucSHA3::SHAKE_Update ( sha3_ctx_t c,
const void *  data,
size_t  len 
)
inlinestatic

Update shake digest with data.

Parameters
cPointer to context.
dataPointer to data.
lenLength of data in bytes.

Definition at line 128 of file XrdOucSHA3.hh.

129  {Update(c, data, len);}

References Update().

+ Here is the call graph for this function:

◆ Update()

void XrdOucSHA3::Update ( XrdOucSHA3::sha3_ctx_t c,
const void *  data,
size_t  len 
)
static

Update digest with data.

Parameters
cPointer to context.
dataPointer to data.
lenLength of data in bytes.

Definition at line 186 of file XrdOucSHA3.cc.

187 {
188  size_t i;
189  int j;
190 
191  j = c->pt;
192  for (i = 0; i < len; i++) {
193  c->st.b[j++] ^= ((const uint8_t *) data)[i];
194  if (j >= c->rsiz) {
195  sha3_keccakf(c->st.q);
196  j = 0;
197  }
198  }
199  c->pt = j;
200 }

References XrdOucSHA3::sha3_ctx_t::pt, XrdOucSHA3::sha3_ctx_t::rsiz, and XrdOucSHA3::sha3_ctx_t::st.

Referenced by Calc(), and SHAKE_Update().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: