sha1.c File Reference

SHA1 hash implementation and interface functions. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "sha1.h"
#include "md5.h"
#include "crypto.h"

Include dependency graph for sha1.c:

Go to the source code of this file.

Defines

#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)

Functions

void hmac_sha1_vector (const u8 *key, size_t key_len, size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
 HMAC-SHA1 over data vector (RFC 2104).
void hmac_sha1 (const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac)
 HMAC-SHA1 over data buffer (RFC 2104).
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)
 SHA1-based Pseudo-Random Function (PRF) (IEEE 802.11i, 8.5.1.1).
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)
 EAP-FAST Pseudo-Random Function (T-PRF).
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)
 Pseudo-Random Function for TLS (TLS-PRF, RFC 2246).
void pbkdf2_sha1 (const char *passphrase, const char *ssid, size_t ssid_len, int iterations, u8 *buf, size_t buflen)
 SHA1-based key derivation function (PBKDF2) for IEEE 802.11i.
void sha1_vector (size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
 SHA-1 hash for data vector.
void sha1_transform (u8 *state, const u8 data[64])
 Perform one SHA-1 transform step.


Detailed Description

SHA1 hash implementation and interface functions.

Copyright
Copyright (c) 2003-2005, Jouni Malinen <[email protected]>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

Alternatively, this software may be distributed under the terms of BSD license.

See README and COPYING for more details.

Definition in file sha1.c.


Define Documentation

#define blk  ) 
 

Value:

(block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \
        block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))

Definition at line 522 of file sha1.c.

#define blk0  ) 
 

Value:

(block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \
        (rol(block->l[i], 8) & 0x00FF00FF))

Definition at line 517 of file sha1.c.

#define R0 v,
w,
x,
y,
z,
 ) 
 

Value:

z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
        w = rol(w, 30);

Definition at line 526 of file sha1.c.

#define R1 v,
w,
x,
y,
z,
 ) 
 

Value:

z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
        w = rol(w, 30);

Definition at line 529 of file sha1.c.

#define R3 v,
w,
x,
y,
z,
 ) 
 

Value:

z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
        w = rol(w, 30);

Definition at line 534 of file sha1.c.

#define R4 v,
w,
x,
y,
z,
 ) 
 

Value:

z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
        w=rol(w, 30);

Definition at line 537 of file sha1.c.


Function Documentation

void hmac_sha1 const u8 *  key,
size_t  key_len,
const u8 *  data,
size_t  data_len,
u8 *  mac
 

HMAC-SHA1 over data buffer (RFC 2104).

Parameters:
key Key for HMAC operations
key_len Length of the key in bytes
data Pointers to the data area
data_len Length of the data area
mac Buffer for the hash (20 bytes)

Definition at line 109 of file sha1.c.

Here is the call graph for this function:

void hmac_sha1_vector const u8 *  key,
size_t  key_len,
size_t  num_elem,
const u8 *  addr[],
const size_t *  len,
u8 *  mac
 

HMAC-SHA1 over data vector (RFC 2104).

Parameters:
key Key for HMAC operations
key_len Length of the key in bytes
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 (20 bytes)

Definition at line 36 of file sha1.c.

Here is the call graph for this function:

void pbkdf2_sha1 const char *  passphrase,
const char *  ssid,
size_t  ssid_len,
int  iterations,
u8 *  buf,
size_t  buflen
 

SHA1-based key derivation function (PBKDF2) for IEEE 802.11i.

Parameters:
passphrase ASCII passphrase
ssid SSID
ssid_len SSID length in bytes
interations Number of iterations to run
buf Buffer for the generated key
buflen 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.

Definition at line 358 of file sha1.c.

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
 

SHA1-based Pseudo-Random Function (PRF) (IEEE 802.11i, 8.5.1.1).

Parameters:
key Key for PRF
key_len Length of the key in bytes
label A unique label for each purpose of the PRF
data Extra data to bind into the key
data_len Length of the data
buf Buffer for the generated pseudo-random key
buf_len 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).

Definition at line 130 of file sha1.c.

Here is the call graph for this function:

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
 

EAP-FAST Pseudo-Random Function (T-PRF).

Parameters:
key Key for PRF
key_len Length of the key in bytes
label A unique label for each purpose of the PRF
seed Seed value to bind into the key
seed_len Length of the seed
buf Buffer for the generated pseudo-random key
buf_len 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.

Definition at line 182 of file sha1.c.

Here is the call graph for this function:

void sha1_transform u8 *  state,
const u8  data[64]
 

Perform one SHA-1 transform step.

Parameters:
state SHA-1 state
data Input data for the SHA-1 transform
This function is used to implement random number generation specified in NIST FIPS Publication 186-2 for EAP-SIM. This PRF uses a function that is similar to SHA-1, but has different message padding and as such, access to just part of the SHA-1 is needed.

Definition at line 424 of file sha1.c.

void sha1_vector size_t  num_elem,
const u8 *  addr[],
const size_t *  len,
u8 *  mac
 

SHA-1 hash for data vector.

Parameters:
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

Definition at line 400 of file sha1.c.

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
 

Pseudo-Random Function for TLS (TLS-PRF, RFC 2246).

Parameters:
secret Key for PRF
secret_len Length of the key in bytes
label A unique label for each purpose of the PRF
seed Seed value to bind into the key
seed_len Length of the seed
out Buffer for the generated pseudo-random key
outlen Number of bytes of key to generate
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.

Definition at line 237 of file sha1.c.

Here is the call graph for this function:


Generated on Sat May 6 21:18:44 2006 for wpa_supplicant by  doxygen 1.4.2