#include "eyefi.h"
#include <string.h>
gehe zum Quellcode dieser Datei
|
#define | SHA1_MAC_LEN 20 |
|
#define | MD5_MAC_LEN 16 |
|
#define | SHA1HANDSOFF |
|
#define | rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) |
|
#define | blk0(i) |
|
#define | blk(i) |
|
#define | R0(v, w, x, y, z, i) |
|
#define | R1(v, w, x, y, z, i) |
|
#define | R2(v, w, x, y, z, i) z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30); |
|
#define | R3(v, w, x, y, z, i) |
|
#define | R4(v, w, x, y, z, i) |
|
|
void | sha1_vector (size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac) |
|
void | hmac_sha1_vector (const u8 *key, size_t key_len, size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac) |
|
void | hmac_sha1 (const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac) |
|
void | sha1_prf (const u8 *key, size_t key_len, const char *label, const u8 *data, size_t data_len, u8 *buf, size_t buf_len) |
|
void | sha1_t_prf (const u8 *key, size_t key_len, const char *label, const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len) |
|
int | tls_prf (const u8 *secret, size_t secret_len, const char *label, const u8 *seed, size_t seed_len, u8 *out, size_t outlen) |
|
static void | pbkdf2_sha1_f (const char *passphrase, const char *ssid, size_t ssid_len, int iterations, unsigned int count, u8 *digest) |
|
void | pbkdf2_sha1 (const char *passphrase, const char *ssid, size_t ssid_len, int iterations, u8 *buf, size_t buflen) |
|
static void | SHA1Init (struct SHA1Context *context) |
|
static void | SHA1Update (struct SHA1Context *context, const void *data, u32 len) |
|
static void | SHA1Final (unsigned char digest[20], struct SHA1Context *context) |
|
static void | SHA1Transform (u32 state[5], const unsigned char buffer[64]) |
|
int | fips186_2_prf (const u8 *seed, size_t seed_len, u8 *x, size_t xlen) |
|
Wert:
Definiert in Zeile 553 der Datei sha1.c.
Wert:
Definiert in Zeile 548 der Datei sha1.c.
#define R0 |
( |
|
v, |
|
|
|
w, |
|
|
|
x, |
|
|
|
y, |
|
|
|
z, |
|
|
|
i |
|
) |
| |
Wert:z += ((
w & (
x ^
y)) ^
y) +
blk0(i) + 0x5A827999 +
rol(v, 5); \
Definiert in Zeile 557 der Datei sha1.c.
#define R1 |
( |
|
v, |
|
|
|
w, |
|
|
|
x, |
|
|
|
y, |
|
|
|
z, |
|
|
|
i |
|
) |
| |
Wert:z += ((
w & (
x ^
y)) ^
y) +
blk(i) + 0x5A827999 +
rol(v, 5); \
Definiert in Zeile 560 der Datei sha1.c.
#define R2 |
( |
|
v, |
|
|
|
w, |
|
|
|
x, |
|
|
|
y, |
|
|
|
z, |
|
|
|
i |
|
) |
| z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30); |
#define R3 |
( |
|
v, |
|
|
|
w, |
|
|
|
x, |
|
|
|
y, |
|
|
|
z, |
|
|
|
i |
|
) |
| |
Wert:z += (((
w |
x) &
y) | (
w &
x)) +
blk(i) + 0x8F1BBCDC +
rol(v, 5); \
Definiert in Zeile 565 der Datei sha1.c.
#define R4 |
( |
|
v, |
|
|
|
w, |
|
|
|
x, |
|
|
|
y, |
|
|
|
z, |
|
|
|
i |
|
) |
| |
Wert:z += (
w ^
x ^
y) +
blk(i) + 0xCA62C1D6 +
rol(v, 5); \
Definiert in Zeile 568 der Datei sha1.c.
#define rol |
( |
|
value, |
|
|
|
bits |
|
) |
| (((value) << (bits)) | ((value) >> (32 - (bits)))) |
Definiert in Zeile 407 der Datei sha1.c.
415 if (seed_len >
sizeof(xkey))
416 seed_len =
sizeof(xkey);
420 memcpy(xkey, seed, seed_len);
421 memset(xkey + seed_len, 0, 64 - seed_len);
429 for (j = 0; j <
m; j++) {
431 for (i = 0; i < 2; i++) {
446 for (k = 19; k >= 0; k--) {
447 carry += xkey[k] + xpos[k];
448 xkey[k] = carry & 0xff;
hmac_sha1 - HMAC-SHA1 over data buffer (RFC 2104) : Key for HMAC operations : Length of the key in bytes : Pointers to the data area : Length of the data area : Buffer for the hash (20 bytes)
Definiert in Zeile 106 der Datei sha1.c.
hmac_sha1_vector - HMAC-SHA1 over data vector (RFC 2104) : Key for HMAC operations : Length of the key in bytes : Number of elements in the data vector : Pointers to the data areas : Lengths of the data blocks : Buffer for the hash (20 bytes)
Definiert in Zeile 35 der Datei sha1.c.
38 unsigned char k_pad[64];
68 memset(k_pad, 0,
sizeof(k_pad));
71 for (i = 0; i < 64; i++)
77 for (i = 0; i < num_elem; i++) {
78 _addr[i + 1] =
addr[i];
83 memset(k_pad, 0,
sizeof(k_pad));
86 for (i = 0; i < 64; i++)
void pbkdf2_sha1 |
( |
const char * |
passphrase, |
|
|
const char * |
ssid, |
|
|
size_t |
ssid_len, |
|
|
int |
iterations, |
|
|
u8 * |
buf, |
|
|
size_t |
buflen |
|
) |
| |
pbkdf2_sha1 - SHA1-based key derivation function (PBKDF2) for IEEE 802.11i : ASCII passphrase : SSID : SSID length in bytes : Number of iterations to run : Buffer for the generated key : Length of the buffer in bytes
This function is used to derive PSK for WPA-PSK. For this protocol, iterations is set to 4096 and buflen to 32. This function is described in IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0.
Definiert in Zeile 352 der Datei sha1.c.
355 unsigned int count = 0;
356 unsigned char *pos =
buf;
357 size_t left = buflen, plen;
365 memcpy(pos, digest, plen);
static void pbkdf2_sha1_f |
( |
const char * |
passphrase, |
|
|
const char * |
ssid, |
|
|
size_t |
ssid_len, |
|
|
int |
iterations, |
|
|
unsigned int |
count, |
|
|
u8 * |
digest |
|
) |
| |
|
static |
Definiert in Zeile 300 der Datei sha1.c.
306 unsigned char count_buf[4];
309 size_t passphrase_len =
strlen(passphrase);
311 addr[0] = (
u8 *) ssid;
322 count_buf[0] = (
count >> 24) & 0xff;
323 count_buf[1] = (
count >> 16) & 0xff;
324 count_buf[2] = (
count >> 8) & 0xff;
325 count_buf[3] =
count & 0xff;
329 for (i = 1; i < iterations; i++) {
334 digest[j] ^= tmp2[j];
sha1_prf - SHA1-based Pseudo-Random Function (PRF) (IEEE 802.11i, 8.5.1.1) : Key for PRF : Length of the key in bytes : A unique label for each purpose of the PRF : Extra data to bind into the key : Length of the data : Buffer for the generated pseudo-random key : Number of bytes of key to generate
This function is used to derive new, cryptographically separate keys from a given key (e.g., PMK in IEEE 802.11i).
Definiert in Zeile 126 der Datei sha1.c.
129 u8 zero = 0, counter = 0;
132 size_t label_len =
strlen(label);
133 const unsigned char *
addr[4];
136 addr[0] = (
u8 *) label;
146 while (pos < buf_len) {
147 plen = buf_len - pos;
sha1_t_prf - EAP-FAST Pseudo-Random Function (T-PRF) : Key for PRF : Length of the key in bytes : A unique label for each purpose of the PRF : Seed value to bind into the key : Length of the seed : Buffer for the generated pseudo-random key : Number of bytes of key to generate
This function is used to derive new, cryptographically separate keys from a given key for EAP-FAST. T-PRF is defined in draft-cam-winget-eap-fast-02.txt, Appendix B.
Definiert in Zeile 177 der Datei sha1.c.
180 unsigned char counter = 0;
183 size_t label_len =
strlen(label);
185 const unsigned char *
addr[5];
190 addr[1] = (
unsigned char *) label;
191 len[1] = label_len + 1;
194 addr[3] = output_len;
199 output_len[0] = (buf_len >> 8) & 0xff;
200 output_len[1] = buf_len & 0xff;
202 while (pos < buf_len) {
204 plen = buf_len - pos;
sha1_vector - SHA-1 hash for data vector : Number of elements in the data vector : Pointers to the data areas : Lengths of the data blocks : Buffer for the hash
Definiert in Zeile 394 der Datei sha1.c.
401 for (i = 0; i < num_elem; i++)
void SHA1Final |
( |
unsigned char |
digest[20], |
|
|
struct SHA1Context * |
context |
|
) |
| |
|
static |
Definiert in Zeile 691 der Datei sha1.c.
694 unsigned char finalcount[8];
696 for (i = 0; i < 8; i++) {
697 finalcount[i] = (
unsigned char)
698 ((context->
count[(i >= 4 ? 0 : 1)] >>
699 ((3-(i & 3)) * 8) ) & 255);
701 SHA1Update(context, (
unsigned char *)
"\200", 1);
702 while ((context->
count[0] & 504) != 448) {
703 SHA1Update(context, (
unsigned char *)
"\0", 1);
707 for (i = 0; i < 20; i++) {
708 digest[i] = (
unsigned char)
709 ((context->
state[i >> 2] >> ((3 - (i & 3)) * 8)) &
Definiert in Zeile 647 der Datei sha1.c.
650 context->
state[0] = 0x67452301;
651 context->
state[1] = 0xEFCDAB89;
652 context->
state[2] = 0x98BADCFE;
653 context->
state[3] = 0x10325476;
654 context->
state[4] = 0xC3D2E1F0;
static void SHA1Transform |
( |
u32 |
state[5], |
|
|
const unsigned char |
buffer[64] |
|
) |
| |
|
static |
Definiert in Zeile 589 der Datei sha1.c.
599 block = (CHAR64LONG16 *) workspace;
602 block = (CHAR64LONG16 *)
buffer;
611 R0(a,b,c,d,e, 0);
R0(e,a,b,c,d, 1);
R0(d,e,a,b,c, 2);
R0(c,d,e,a,b, 3);
612 R0(b,c,d,e,a, 4);
R0(a,b,c,d,e, 5);
R0(e,a,b,c,d, 6);
R0(d,e,a,b,c, 7);
613 R0(c,d,e,a,b, 8);
R0(b,c,d,e,a, 9);
R0(a,b,c,d,e,10);
R0(e,a,b,c,d,11);
614 R0(d,e,a,b,c,12);
R0(c,d,e,a,b,13);
R0(b,c,d,e,a,14);
R0(a,b,c,d,e,15);
615 R1(e,a,b,c,d,16);
R1(d,e,a,b,c,17);
R1(c,d,e,a,b,18);
R1(b,c,d,e,a,19);
616 R2(a,b,c,d,e,20);
R2(e,a,b,c,d,21);
R2(d,e,a,b,c,22);
R2(c,d,e,a,b,23);
617 R2(b,c,d,e,a,24);
R2(a,b,c,d,e,25);
R2(e,a,b,c,d,26);
R2(d,e,a,b,c,27);
618 R2(c,d,e,a,b,28);
R2(b,c,d,e,a,29);
R2(a,b,c,d,e,30);
R2(e,a,b,c,d,31);
619 R2(d,e,a,b,c,32);
R2(c,d,e,a,b,33);
R2(b,c,d,e,a,34);
R2(a,b,c,d,e,35);
620 R2(e,a,b,c,d,36);
R2(d,e,a,b,c,37);
R2(c,d,e,a,b,38);
R2(b,c,d,e,a,39);
621 R3(a,b,c,d,e,40);
R3(e,a,b,c,d,41);
R3(d,e,a,b,c,42);
R3(c,d,e,a,b,43);
622 R3(b,c,d,e,a,44);
R3(a,b,c,d,e,45);
R3(e,a,b,c,d,46);
R3(d,e,a,b,c,47);
623 R3(c,d,e,a,b,48);
R3(b,c,d,e,a,49);
R3(a,b,c,d,e,50);
R3(e,a,b,c,d,51);
624 R3(d,e,a,b,c,52);
R3(c,d,e,a,b,53);
R3(b,c,d,e,a,54);
R3(a,b,c,d,e,55);
625 R3(e,a,b,c,d,56);
R3(d,e,a,b,c,57);
R3(c,d,e,a,b,58);
R3(b,c,d,e,a,59);
626 R4(a,b,c,d,e,60);
R4(e,a,b,c,d,61);
R4(d,e,a,b,c,62);
R4(c,d,e,a,b,63);
627 R4(b,c,d,e,a,64);
R4(a,b,c,d,e,65);
R4(e,a,b,c,d,66);
R4(d,e,a,b,c,67);
628 R4(c,d,e,a,b,68);
R4(b,c,d,e,a,69);
R4(a,b,c,d,e,70);
R4(e,a,b,c,d,71);
629 R4(d,e,a,b,c,72);
R4(c,d,e,a,b,73);
R4(b,c,d,e,a,74);
R4(a,b,c,d,e,75);
630 R4(e,a,b,c,d,76);
R4(d,e,a,b,c,77);
R4(c,d,e,a,b,78);
R4(b,c,d,e,a,79);
638 a = b = c = d = e = 0;
Definiert in Zeile 661 der Datei sha1.c.
664 const unsigned char *data = _data;
667 SHAPrintContext(context,
"before");
669 j = (context->
count[0] >> 3) & 63;
673 if ((j +
len) > 63) {
676 for ( ; i + 63 <
len; i += 64) {
684 SHAPrintContext(context,
"after ");
tls_prf - Pseudo-Random Function for TLS (TLS-PRF, RFC 2246) : Key for PRF : Length of the key in bytes : A unique label for each purpose of the PRF : Seed value to bind into the key : Length of the seed : Buffer for the generated pseudo-random key : Number of bytes of key to generate Returns: 0 on success, -1 on failure.
This function is used to derive new, cryptographically separate keys from a given key in TLS. This PRF is defined in RFC 2246, Chapter 5.
Definiert in Zeile 232 der Datei sha1.c.
235 size_t L_S1, L_S2, i;
239 int MD5_pos, SHA1_pos;
240 const u8 *MD5_addr[3];
242 const unsigned char *SHA1_addr[3];
250 MD5_addr[1] = (
unsigned char *) label;
251 MD5_len[1] =
strlen(label);
253 MD5_len[2] = seed_len;
255 SHA1_addr[0] = A_SHA1;
257 SHA1_addr[1] = (
unsigned char *) label;
258 SHA1_len[1] =
strlen(label);
260 SHA1_len[2] = seed_len;
268 L_S1 = L_S2 = (secret_len + 1) / 2;
277 for (i = 0; i < outlen; i++) {
290 out[i] = P_MD5[MD5_pos] ^ P_SHA1[SHA1_pos];