#include <gpxe/crypto.h>#include <gpxe/arc4.h>Go to the source code of this file.
Defines | |
| #define | SWAP(ary, i, j) ({ u8 temp = ary[i]; ary[i] = ary[j]; ary[j] = temp; }) |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static int | arc4_setkey (void *ctxv, const void *keyv, size_t keylen) |
| Set ARC4 key. | |
| static void | arc4_xor (void *ctxv, const void *srcv, void *dstv, size_t len) |
| Perform ARC4 encryption or decryption. | |
| static void | arc4_setiv (void *ctx __unused, const void *iv __unused) |
| void | arc4_skip (const void *key, size_t keylen, size_t skip, const void *src, void *dst, size_t msglen) |
| Perform ARC4 encryption or decryption, skipping initial keystream bytes. | |
Variables | |
| struct cipher_algorithm | arc4_algorithm |
| #define SWAP | ( | ary, | |||
| i, | |||||
| j | ) | ({ u8 temp = ary[i]; ary[i] = ary[j]; ary[j] = temp; }) |
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static int arc4_setkey | ( | void * | ctxv, | |
| const void * | keyv, | |||
| size_t | keylen | |||
| ) | [static] |
Set ARC4 key.
| ctxv | ARC4 encryption context | |
| keyv | Key to set | |
| keylen | Length of key |
setiv function because there is no standard length for an initialisation vector in the cipher.
Definition at line 41 of file arc4.c.
References arc4_ctx::i, arc4_ctx::j, S(), arc4_ctx::state, SWAP, and u8.
Referenced by arc4_skip().
00042 { 00043 struct arc4_ctx *ctx = ctxv; 00044 const u8 *key = keyv; 00045 u8 *S = ctx->state; 00046 int i, j; 00047 00048 for ( i = 0; i < 256; i++ ) { 00049 S[i] = i; 00050 } 00051 00052 for ( i = j = 0; i < 256; i++ ) { 00053 j = ( j + S[i] + key[i % keylen] ) & 0xff; 00054 SWAP ( S, i, j ); 00055 } 00056 00057 ctx->i = ctx->j = 0; 00058 return 0; 00059 }
| static void arc4_xor | ( | void * | ctxv, | |
| const void * | srcv, | |||
| void * | dstv, | |||
| size_t | len | |||
| ) | [static] |
Perform ARC4 encryption or decryption.
| ctxv | ARC4 encryption context | |
| srcv | Data to encrypt or decrypt | |
| dstv | Location to store encrypted or decrypted data | |
| len | Length of data to operate on |
If you pass a NULL source or destination pointer, len keystream bytes will be consumed without encrypting any data.
Definition at line 77 of file arc4.c.
References arc4_ctx::i, arc4_ctx::j, S(), src, arc4_ctx::state, SWAP, and u8.
Referenced by arc4_skip().
00079 { 00080 struct arc4_ctx *ctx = ctxv; 00081 const u8 *src = srcv; 00082 u8 *dst = dstv; 00083 u8 *S = ctx->state; 00084 int i = ctx->i, j = ctx->j; 00085 00086 while ( len-- ) { 00087 i = ( i + 1 ) & 0xff; 00088 j = ( j + S[i] ) & 0xff; 00089 SWAP ( S, i, j ); 00090 if ( srcv && dstv ) 00091 *dst++ = *src++ ^ S[(S[i] + S[j]) & 0xff]; 00092 } 00093 00094 ctx->i = i; 00095 ctx->j = j; 00096 }
| static void arc4_setiv | ( | void *ctx | __unused, | |
| const void *iv | __unused | |||
| ) | [static] |
| void arc4_skip | ( | const void * | key, | |
| size_t | keylen, | |||
| size_t | skip, | |||
| const void * | src, | |||
| void * | dst, | |||
| size_t | msglen | |||
| ) |
Perform ARC4 encryption or decryption, skipping initial keystream bytes.
| key | ARC4 encryption key | |
| keylen | Key length | |
| skip | Number of bytes of keystream to skip | |
| src | Message to encrypt or decrypt | |
| msglen | Length of message |
| dst | Encrypted or decrypted message |
Definition at line 114 of file arc4.c.
References arc4_setkey(), arc4_xor(), and NULL.
Referenced by tkip_kie_decrypt().
00116 { 00117 struct arc4_ctx ctx; 00118 arc4_setkey ( &ctx, key, keylen ); 00119 arc4_xor ( &ctx, NULL, NULL, skip ); 00120 arc4_xor ( &ctx, src, dst, msglen ); 00121 }
| struct cipher_algorithm arc4_algorithm |
Initial value:
{
.name = "ARC4",
.ctxsize = ARC4_CTX_SIZE,
.blocksize = 1,
.setkey = arc4_setkey,
.setiv = arc4_setiv,
.encrypt = arc4_xor,
.decrypt = arc4_xor,
}
Definition at line 123 of file arc4.c.
Referenced by tkip_decrypt(), tkip_encrypt(), wep_decrypt(), and wep_encrypt().
1.5.7.1