iPXE
md4.c File Reference

MD4 algorithm. More...

#include <stdint.h>
#include <assert.h>
#include <ipxe/rotate.h>
#include <ipxe/crypto.h>
#include <ipxe/md4.h>

Go to the source code of this file.

Data Structures

struct  md4_variables
 MD4 variables. More...
struct  md4_step
 An MD4 step function. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static uint32_t md4_f_0_15 (struct md4_variables *v, unsigned int i)
 f(b,c,d,w) for steps 0 to 15
static uint32_t md4_f_16_31 (struct md4_variables *v, unsigned int i)
 f(b,c,d,w) for steps 16 to 31
static uint32_t md4_f_32_47 (struct md4_variables *v, unsigned int i)
 f(b,c,d,w) for steps 32 to 47
static void md4_compress (struct md4_digest_data *dd, const struct md4_digest *digest)
 Calculate MD4 digest of accumulated data.
 MDHASH_ALGORITHM (md4, md4_algorithm, md4_compress, __LITTLE_ENDIAN, struct md4_digest_data, md4_init, MD4_DIGEST_SIZE)
 MD4 algorithm.

Variables

static const uint8_t r [3][4]
 MD4 shift amounts.
static const struct md4_step md4_steps [4]
 MD4 steps.
static const struct md4_digest md4_init
 MD4 initial digest values.

Detailed Description

MD4 algorithm.

Definition in file md4.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ md4_f_0_15()

uint32_t md4_f_0_15 ( struct md4_variables * v,
unsigned int i )
static

f(b,c,d,w) for steps 0 to 15

Parameters
vMD4 variables
iIndex within round
Return values
ff(b,c,d,w)

Definition at line 63 of file md4.c.

63 {
64 return ( ( ( v->b & v->c ) | ( ~v->b & v->d ) ) + v->w[i] );
65}
uint32_t c
Definition md4.c:44
uint32_t b
Definition md4.c:43
uint32_t w[16]
Definition md4.c:46
uint32_t d
Definition md4.c:45

References md4_variables::b, md4_variables::c, md4_variables::d, and md4_variables::w.

◆ md4_f_16_31()

uint32_t md4_f_16_31 ( struct md4_variables * v,
unsigned int i )
static

f(b,c,d,w) for steps 16 to 31

Parameters
vMD4 variables
iIndex within round
Return values
ff(b,c,d,w)

Definition at line 74 of file md4.c.

74 {
75 return ( ( ( v->b & v->c ) | ( v->b & v->d ) | ( v->c & v->d ) ) +
76 v->w[ ( ( i << 2 ) | ( i >> 2 ) ) % 16 ] );
77}

References md4_variables::b, md4_variables::c, md4_variables::d, and md4_variables::w.

◆ md4_f_32_47()

uint32_t md4_f_32_47 ( struct md4_variables * v,
unsigned int i )
static

f(b,c,d,w) for steps 32 to 47

Parameters
vMD4 variables
iIndex within round
Return values
ff(b,c,d,w)

Definition at line 86 of file md4.c.

86 {
87 static const uint8_t reverse[16] = {
88 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
89 };
90 return ( ( v->b ^ v->c ^ v->d ) + v->w[reverse[i]] );
91}
unsigned char uint8_t
Definition stdint.h:10

References md4_variables::b, md4_variables::c, md4_variables::d, and md4_variables::w.

◆ md4_compress()

void md4_compress ( struct md4_digest_data * dd,
const struct md4_digest * digest )
static

Calculate MD4 digest of accumulated data.

Parameters
ddDigest and data block
digestCopy of current digest value

Definition at line 128 of file md4.c.

129 {
130 union {
131 struct md4_digest_data dd;
132 struct md4_variables v;
133 } *u = container_of ( dd, typeof ( *u ), dd );
134 struct md4_variables *v = &u->v;
135 const struct md4_step *step;
136 uint32_t *a = &v->a;
137 uint32_t *b = &v->b;
138 uint32_t *c = &v->c;
139 uint32_t *d = &v->d;
140 uint32_t *w = v->w;
141 uint32_t f;
142 uint32_t temp;
143 unsigned int round;
144 unsigned int i;
145
146 /* Sanity checks */
147 build_assert ( &u->dd.digest.h[0] == a );
148 build_assert ( &u->dd.digest.h[1] == b );
149 build_assert ( &u->dd.digest.h[2] == c );
150 build_assert ( &u->dd.digest.h[3] == d );
151 build_assert ( &u->dd.data.dword[0] == w );
152 build_assert ( sizeof ( u->dd ) == sizeof ( u->v ) );
153
154 /* Main loop */
155 for ( i = 0 ; i < 48 ; i++ ) {
156 round = ( i / 16 );
157 step = &md4_steps[round];
158 f = step->f ( v, ( i % 16 ) );
159 temp = *d;
160 *d = *c;
161 *c = *b;
162 *b = rol32 ( ( *a + f + step->constant ), r[round][ i % 4 ] );
163 *a = temp;
164 DBGC2 ( &md4_algorithm, "%2d : %08x %08x %08x %08x\n",
165 i, *a, *b, *c, *d );
166 }
167
168 /* Add chunk to hash */
169 for ( i = 0 ; i < 4 ; i++ )
170 dd->digest.h[i] += digest->h[i];
171}
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
unsigned int uint32_t
Definition stdint.h:12
#define build_assert(condition)
Assert a condition at build time (after dead code elimination).
Definition assert.h:77
union @104331263140136355135267063077374276003064103115 u
#define DBGC2(...)
Definition compiler.h:547
static const uint8_t r[3][4]
MD4 shift amounts.
Definition md4.c:50
static const struct md4_step md4_steps[4]
MD4 steps.
Definition md4.c:108
struct digest_algorithm md4_algorithm
void step(void)
Single-step a single process.
Definition process.c:99
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
MD4 digest and data block.
Definition md4.h:43
struct md4_digest digest
Digest of data already processed.
Definition md4.h:45
uint32_t h[4]
Hash output.
Definition md4.h:20
An MD4 step function.
Definition md4.c:94
uint32_t(* f)(struct md4_variables *v, unsigned int i)
Calculate f(b,c,d,w).
Definition md4.c:102
MD4 variables.
Definition md4.c:40
uint32_t a
Definition md4.c:42
static u32 rol32(u32 v, int bits)
Rotate 32-bit value left.
Definition wpa_tkip.c:174

References md4_variables::a, md4_variables::b, build_assert, md4_variables::c, container_of, md4_variables::d, DBGC2, md4_digest_data::digest, md4_step::f, md4_digest::h, md4_algorithm, md4_steps, r, rol32(), step(), typeof(), u, and md4_variables::w.

Referenced by MDHASH_ALGORITHM().

◆ MDHASH_ALGORITHM()

Variable Documentation

◆ r

const uint8_t r[3][4]
static
Initial value:
= {
{ 3, 7, 11, 19 },
{ 3, 5, 9, 13 },
{ 3, 9, 11, 15 },
}

MD4 shift amounts.

Definition at line 50 of file md4.c.

50 {
51 { 3, 7, 11, 19 },
52 { 3, 5, 9, 13 },
53 { 3, 9, 11, 15 },
54};

Referenced by __ath9k_hw_init(), __attribute__(), af_packet_nic_poll(), ar5008_write_rf_array(), ath9k_hw_channel_change(), ath9k_hw_reset(), ath9k_hw_write_array(), ath9k_start(), ath_radio_disable(), ath_reset(), ath_set_channel(), bcom_phy_init(), ecdsa_alloc(), ecdsa_sign_rs(), ecdsa_verify_rs(), fls(), genesis_mac_init(), gma_write16(), gma_write16(), md4_compress(), md5_compress(), tap_poll(), xm_write16(), and xm_write32().

◆ md4_steps

const struct md4_step md4_steps[4]
static
Initial value:
= {
{ .f = md4_f_0_15, .constant = 0x00000000UL },
{ .f = md4_f_16_31, .constant = 0x5a827999UL },
{ .f = md4_f_32_47, .constant = 0x6ed9eba1UL },
}
static uint32_t md4_f_32_47(struct md4_variables *v, unsigned int i)
f(b,c,d,w) for steps 32 to 47
Definition md4.c:86
static uint32_t md4_f_16_31(struct md4_variables *v, unsigned int i)
f(b,c,d,w) for steps 16 to 31
Definition md4.c:74
static uint32_t md4_f_0_15(struct md4_variables *v, unsigned int i)
f(b,c,d,w) for steps 0 to 15
Definition md4.c:63

MD4 steps.

Definition at line 108 of file md4.c.

108 {
109 /** 0 to 15 */
110 { .f = md4_f_0_15, .constant = 0x00000000UL },
111 /** 16 to 31 */
112 { .f = md4_f_16_31, .constant = 0x5a827999UL },
113 /** 32 to 47 */
114 { .f = md4_f_32_47, .constant = 0x6ed9eba1UL },
115};

Referenced by md4_compress().

◆ md4_init

const struct md4_digest md4_init
static
Initial value:
= {
.h = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }
}

MD4 initial digest values.

Definition at line 118 of file md4.c.

118 {
119 .h = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }
120};

Referenced by MDHASH_ALGORITHM().