libosmogsm 1.13.1.1-afb4 Osmocom GSM library

Macros | Functions | Variables
sha256-internal.c File Reference
`#include "common.h"`
`#include "sha256.h"`
`#include "sha256_i.h"`
`#include "crypto.h"`

## Macros
#define | RORc(x, y)
#define | Ch(x, y, z) (z ^ (x & (y ^ z)))
#define | Maj(x, y, z) (((x | y) & z) | (x & y))
#define | S(x, n) RORc((x), (n))
#define | R(x, n) (((x)&0xFFFFFFFFUL)>>(n))
#define | Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22))
#define | Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25))
#define | Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3))
#define | Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10))
#define | MIN(x, y) (((x) < (y)) ? (x) : (y))
#define | RND(a, b, c, d, e, f, g, h, i)

## Functions
int | sha256_vector (size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
| sha256_vector - SHA256 hash for data vector @num_elem: Number of elements in the data vector @addr: Pointers to the data areas @len: Lengths of the data blocks @mac: Buffer for the hash Returns: 0 on success, -1 of failure More...
static int | sha256_compress (struct sha256_state *md, unsigned char *buf)
void | sha256_init (struct sha256_state *md)
int | sha256_process (struct sha256_state *md, const unsigned char *in, unsigned long inlen)
| Process a block of memory though the hash. More...
int | sha256_done (struct sha256_state *md, unsigned char *out)
| Terminate the hash to get the digest. More...

## Variables
static const unsigned long | K [64]

## Macro Definition Documentation

## ◆ Ch

#define Ch | ( |  | x,
|  |  | y,
|  |  | z
| ) |  | (z ^ (x & (y ^ z)))

## ◆ Gamma0

#define Gamma0 | ( |  | x | ) | (S(x, 7) ^ S(x, 18) ^ R(x, 3))

## ◆ Gamma1

#define Gamma1 | ( |  | x | ) | (S(x, 17) ^ S(x, 19) ^ R(x, 10))

## ◆ Maj

#define Maj | ( |  | x,
|  |  | y,
|  |  | z
| ) |  | (((x | y) & z) | (x & y))

## ◆ MIN

#define MIN | ( |  | x,
|  |  | y
| ) |  | (((x) < (y)) ? (x) : (y))

## ◆ R

#define R | ( |  | x,
|  |  | n
| ) |  | (((x)&0xFFFFFFFFUL)>>(n))

## ◆ RND

#define RND | ( |  | a,
|  |  | b,
|  |  | c,
|  |  | d,
|  |  | e,
|  |  | f,
|  |  | g,
|  |  | h,
|  |  | i
| ) |  |

Value:
t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
t1 = Sigma0(a) + Maj(a, b, c); \
d += t0; \
h = t0 + t1;
g
struct osmo_tdef_group * g
c
struct abis_rsl_common_hdr c
Definition: gsm_08_58.h:0
h
struct gad_raw_head h
type = GAD_TYPE_ELL_POINT
Definition: gsm_23_032.h:0
Maj
#define Maj(x, y, z)
Definition: sha256-internal.c:74
Sigma0
#define Sigma0(x)
Definition: sha256-internal.c:77
Sigma1
#define Sigma1(x)
Definition: sha256-internal.c:78
Ch
#define Ch(x, y, z)
Definition: sha256-internal.c:73
K
static const unsigned long K[64]
Definition: sha256-internal.c:52

## ◆ RORc

#define RORc | ( |  | x,
|  |  | y
| ) |  |

Value:
( ((((unsigned long) (x) & 0xFFFFFFFFUL) >> (unsigned long) ((y) & 31)) | \
((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)
x
uint32_t x

## ◆ S

#define S | ( |  | x,
|  |  | n
| ) |  | RORc((x), (n))

## ◆ Sigma0

#define Sigma0 | ( |  | x | ) | (S(x, 2) ^ S(x, 13) ^ S(x, 22))

## ◆ Sigma1

#define Sigma1 | ( |  | x | ) | (S(x, 6) ^ S(x, 11) ^ S(x, 25))

## Function Documentation

## ◆ sha256_compress()

static int sha256_compress | ( | struct sha256_state * | md,
|  | unsigned char * | buf
| ) |  |
| static

References sha256_state::buf, Gamma0, Gamma1, RND, S, sha256_state::state, and WPA_GET_BE32.

Referenced by sha256_done(), and sha256_process().

## ◆ sha256_done()

int sha256_done | ( | struct sha256_state * | md,
|  | unsigned char * | out
| ) |  |

Terminate the hash to get the digest.

Parameters

  md | The hash state
  out | [out] The destination of the hash (32 bytes)

Returns
  CRYPT_OK if successful

References sha256_state::buf, sha256_state::curlen, sha256_state::length, SHA256_BLOCK_SIZE, sha256_compress(), sha256_state::state, WPA_PUT_BE32, and WPA_PUT_BE64.

Referenced by sha256_vector().

## ◆ sha256_init()

void sha256_init | ( | struct sha256_state * | md | ) |

References sha256_state::curlen, sha256_state::length, and sha256_state::state.

Referenced by sha256_vector().

## ◆ sha256_process()

int sha256_process | ( | struct sha256_state * | md,
|  | const unsigned char * | in,
|  | unsigned long | inlen
| ) |  |

Process a block of memory though the hash.

Parameters

  md | The hash state
  in | The data to hash
  inlen | The length of the data (octets)

Returns
  CRYPT_OK if successful

References sha256_state::buf, sha256_state::curlen, sha256_state::length, MIN, n, os_memcpy, SHA256_BLOCK_SIZE, and sha256_compress().

Referenced by sha256_vector().

## ◆ sha256_vector()

int sha256_vector | ( | size_t | num_elem,
|  | const u8 * | addr[],
|  | const size_t * | len,
|  | u8 * | mac
| ) |  |

sha256_vector - SHA256 hash for data vector @num_elem: Number of elements in the data vector @addr: Pointers to the data areas @len: Lengths of the data blocks @mac: Buffer for the hash Returns: 0 on success, -1 of failure

sha256_vector - SHA256 hash for data vector @num_elem: Number of elements in the data vector @addr: Pointers to the data areas @len: Lengths of the data blocks @mac: Buffer for the hash Returns: 0 on success, -1 on failure

References len, sha256_done(), sha256_init(), and sha256_process().

Referenced by hmac_sha256_vector().

## Variable Documentation

## ◆ K

const unsigned long K[64]
| static

Initial value:
= {
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
}