UFO: Alien Invasion
Loading...
Searching...
No Matches
sha2.cpp File Reference
#include <string.h>
#include <stdio.h>
#include "sha2.h"
#include "filesys.h"
#include "../shared/shared.h"
Include dependency graph for sha2.cpp:

Go to the source code of this file.

Macros

#define _CRT_SECURE_NO_DEPRECATE   1
#define GET_UINT32_BE(n, b, i)
#define PUT_UINT32_BE(n, b, i)
#define SHR(x, n)
#define ROTR(x, n)
#define S0(x)
#define S1(x)
#define S2(x)
#define S3(x)
#define F0(x, y, z)
#define F1(x, y, z)
#define R(t)
#define P(a, b, c, d, e, f, g, h, x, K)

Functions

void Com_SHA2Starts (sha2_context *ctx)
static void Com_SHA2Process (sha2_context *ctx, const byte data[64])
void Com_SHA2Update (sha2_context *ctx, const byte *input, uint32_t length)
void Com_SHA2Finish (sha2_context *ctx, byte digest[32])
bool Com_SHA2File (const char *filename, byte digest[32])
 Output SHA-256(file contents).
void Com_SHA2Csum (const byte *buf, uint32_t buflen, byte digest[32])
 Output SHA-256(buf).
void Com_SHA2ToHex (const byte digest[32], char final[65])
void Com_SHA2Hmac (const byte *buf, uint32_t buflen, const byte *key, uint32_t keylen, byte digest[32])
 Output HMAC-SHA-256(buf,key).

Variables

static const byte sha2_padding [64]

Macro Definition Documentation

◆ _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_DEPRECATE   1

Definition at line 27 of file sha2.cpp.

◆ F0

#define F0 ( x,
y,
z )
Value:
((x & y) | (z & (x | y)))

◆ F1

#define F1 ( x,
y,
z )
Value:
(z ^ (x & (y ^ z)))

◆ GET_UINT32_BE

#define GET_UINT32_BE ( n,
b,
i )
Value:
{ \
(n) = ( (uint64_t) (b)[(i) ] << 24 ) \
| ( (uint64_t) (b)[(i) + 1] << 16 ) \
| ( (uint64_t) (b)[(i) + 2] << 8 ) \
| ( (uint64_t) (b)[(i) + 3] ); \
}
QGL_EXTERN GLint i
Definition r_gl.h:113

32-bit integer manipulation macros (big endian)

Definition at line 41 of file sha2.cpp.

Referenced by Com_SHA2Process().

◆ P

#define P ( a,
b,
c,
d,
e,
f,
g,
h,
x,
K )
Value:
{ \
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
temp2 = S2(a) + F0(a,b,c); \
d += temp1; h = temp1 + temp2; \
}
#define F1(x, y, z)
Definition md5.cpp:65
QGL_EXTERN GLfloat f
Definition r_gl.h:114
#define S2(x)
#define F0(x, y, z)
#define S3(x)

Referenced by Com_SHA2Process().

◆ PUT_UINT32_BE

#define PUT_UINT32_BE ( n,
b,
i )
Value:
{ \
(b)[(i) ] = (byte) ( (n) >> 24 ); \
(b)[(i) + 1] = (byte) ( (n) >> 16 ); \
(b)[(i) + 2] = (byte) ( (n) >> 8 ); \
(b)[(i) + 3] = (byte) ( (n) ); \
}
uint8_t byte
Definition ufotypes.h:34

Definition at line 50 of file sha2.cpp.

Referenced by Com_SHA2Finish().

◆ R

#define R ( t)
Value:
( \
W[t] = S1(W[t - 2]) + W[t - 7] + \
S0(W[t - 15]) + W[t - 16] \
)
#define S1(x)

Referenced by Com_SHA2Process().

◆ ROTR

#define ROTR ( x,
n )
Value:
(SHR(x,n) | (x << (32 - n)))
#define SHR(x, n)

◆ S0

#define S0 ( x)
Value:
(ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
#define ROTR(x, n)

◆ S1

#define S1 ( x)
Value:
(ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))

◆ S2

#define S2 ( x)
Value:
(ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))

◆ S3

#define S3 ( x)
Value:
(ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))

◆ SHR

#define SHR ( x,
n )
Value:
((x & 0xFFFFFFFF) >> n)

Function Documentation

◆ Com_SHA2Csum()

void Com_SHA2Csum ( const byte * buf,
uint32_t buflen,
byte digest[32] )

Output SHA-256(buf).

Definition at line 292 of file sha2.cpp.

References Com_SHA2Finish(), Com_SHA2Starts(), and Com_SHA2Update().

Referenced by TEST_F().

◆ Com_SHA2File()

bool Com_SHA2File ( const char * filename,
byte digest[32] )

Output SHA-256(file contents).

Returns
true if successful

Definition at line 270 of file sha2.cpp.

References Com_SHA2Finish(), Com_SHA2Starts(), Com_SHA2Update(), f, FILE_READ, FS_OpenFile(), and FS_Read().

◆ Com_SHA2Finish()

void Com_SHA2Finish ( sha2_context * ctx,
byte digest[32] )

◆ Com_SHA2Hmac()

void Com_SHA2Hmac ( const byte * buf,
uint32_t buflen,
const byte * key,
uint32_t keylen,
byte digest[32] )

Output HMAC-SHA-256(buf,key).

Definition at line 308 of file sha2.cpp.

References Com_SHA2Finish(), Com_SHA2Starts(), Com_SHA2Update(), i, and key.

◆ Com_SHA2Process()

void Com_SHA2Process ( sha2_context * ctx,
const byte data[64] )
static

Definition at line 77 of file sha2.cpp.

References data, E, F, G, GET_UINT32_BE, H, P, R, and sha2_context::state.

Referenced by Com_SHA2Update().

◆ Com_SHA2Starts()

void Com_SHA2Starts ( sha2_context * ctx)

Core SHA-256 functions

Definition at line 62 of file sha2.cpp.

References sha2_context::state, and sha2_context::total.

Referenced by Com_SHA2Csum(), Com_SHA2File(), and Com_SHA2Hmac().

◆ Com_SHA2ToHex()

void Com_SHA2ToHex ( const byte digest[32],
char final[65] )

Definition at line 301 of file sha2.cpp.

References i, and Q_strcat().

Referenced by TEST_F().

◆ Com_SHA2Update()

void Com_SHA2Update ( sha2_context * ctx,
const byte * input,
uint32_t length )

Variable Documentation

◆ sha2_padding

const byte sha2_padding[64]
static
Initial value:
=
{ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

Definition at line 240 of file sha2.cpp.

Referenced by Com_SHA2Finish().