source
code documentation
des.c File Reference
Detailed Description
code for DES and 3DES in CBC mode
- Author:
- Niklaus Schild <n.schild@gmx.ch>
OUTLINE: This module contains mainly code extracted from the libssl library. We use this code to implement a DES73DES-CBC.
IMPLEMENTATION: "This product includes cryptographic software written by Eric Young (eay@cryptsoft.com)" (taken form www.openssl.org)"
NOTES:
This document is part of embedded IPsec
Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
All rights reserved.
This file contains code from the OpenSSL Project
portions Copyright (c) 1998-2003 OpenSSL (www.openssl.org)
Definition in file des.c.
#include <string.h>
#include "ipsec/des.h"
#include "ipsec/debug.h"
Go to the source code of this file.
|
Defines |
#define | DES_KEY_SZ (sizeof(DES_cblock)) |
#define | DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) |
#define | ITERATIONS 16 |
#define | HALF_ITERATIONS 8 |
#define | c2l(c, l) |
#define | c2ln(c, l1, l2, n) |
#define | l2c(l, c) |
#define | HDRSIZE 4 |
#define | n2l(c, l) |
#define | l2n(l, c) |
#define | l2cn(l1, l2, c, n) |
#define | ROTATE(a, n) (((a)>>(n))+((a)<<(32-(n)))) |
#define | LOAD_DATA_tmp(a, b, c, d, e, f) LOAD_DATA(a,b,c,d,e,f,g) |
#define | LOAD_DATA(R, S, u, t, E0, E1, tmp) |
#define | D_ENCRYPT(LL, R, S) |
#define | PERM_OP(a, b, t, n, m) |
#define | IP(l, r) |
#define | FP(l, r) |
#define | NUM_WEAK_KEY 16 |
#define | HPERM_OP(a, t, n, m) |
Functions |
void | DES_cbc_encrypt (const unsigned char *input, unsigned char *output, long length, DES_key_schedule *schedule, DES_cblock *ivec, int enc) |
void | DES_ncbc_encrypt (const unsigned char *input, unsigned char *output, long length, DES_key_schedule *schedule, DES_cblock *ivec, int enc) |
void | DES_encrypt1 (DES_LONG *data, DES_key_schedule *ks, int enc) |
void | DES_encrypt2 (DES_LONG *data, DES_key_schedule *ks, int enc) |
void | DES_encrypt3 (DES_LONG *data, DES_key_schedule *ks1, DES_key_schedule *ks2, DES_key_schedule *ks3) |
void | DES_decrypt3 (DES_LONG *data, DES_key_schedule *ks1, DES_key_schedule *ks2, DES_key_schedule *ks3) |
void | DES_ede3_cbc_encrypt (const unsigned char *input, unsigned char *output, long length, DES_key_schedule *ks1, DES_key_schedule *ks2, DES_key_schedule *ks3, DES_cblock *ivec, int enc) |
void | DES_set_odd_parity (DES_cblock *key) |
int | DES_check_key_parity (const_DES_cblock *key) |
int | DES_is_weak_key (const_DES_cblock *key) |
int | DES_set_key (const_DES_cblock *key, DES_key_schedule *schedule) |
int | DES_key_sched (const_DES_cblock *key, DES_key_schedule *schedule) |
int | DES_set_key_checked (const_DES_cblock *key, DES_key_schedule *schedule) |
void | DES_set_key_unchecked (const_DES_cblock *key, DES_key_schedule *schedule) |
void | cipher_3des_cbc (unsigned char *text, int text_len, unsigned char *key, unsigned char *iv, int mode, unsigned char *output) |
Variables |
const DES_LONG | DES_SPtrans [8][64] |
int | _shadow_DES_check_key |
const unsigned char | odd_parity [256] |
DES_cblock | weak_keys [NUM_WEAK_KEY] |
const DES_LONG | des_skb [8][64] |
Define Documentation
|
Value:
Definition at line 245 of file des.c. |
#define c2ln |
( |
c, |
|
|
l1, |
|
|
l2, |
|
|
n |
|
) |
|
|
|
Value: { \
c+=n; \
l1=l2=0; \
switch (n) { \
case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
case 5: l2|=((DES_LONG)(*(--(c)))); \
case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
case 1: l1|=((DES_LONG)(*(--(c)))); \
} \
}
Definition at line 253 of file des.c. |
#define D_ENCRYPT |
( |
LL, |
|
|
R, |
|
|
S |
|
) |
|
|
|
Value:
Definition at line 325 of file des.c. |
|
Value: { \
DES_LONG tt; \
PERM_OP(l,r,tt, 1,0x55555555L); \
PERM_OP(r,l,tt, 8,0x00ff00ffL); \
PERM_OP(l,r,tt, 2,0x33333333L); \
PERM_OP(r,l,tt,16,0x0000ffffL); \
PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
}
Definition at line 393 of file des.c. |
#define HALF_ITERATIONS 8
|
|
#define HPERM_OP |
( |
a, |
|
|
t, |
|
|
n, |
|
|
m |
|
) |
|
|
|
Value: ((t)=((((a)<<(16-(n)))^(a))&(m)),\
(a)=(a)^(t)^(t>>(16-(n))))
Definition at line 815 of file des.c. |
|
Value: { \
DES_LONG tt; \
PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
PERM_OP(l,r,tt,16,0x0000ffffL); \
PERM_OP(r,l,tt, 2,0x33333333L); \
PERM_OP(l,r,tt, 8,0x00ff00ffL); \
PERM_OP(r,l,tt, 1,0x55555555L); \
}
Definition at line 383 of file des.c. |
|
Value: (*((c)++)=(unsigned char)(((l) )&0xff), \
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
Definition at line 270 of file des.c. |
#define l2cn |
( |
l1, |
|
|
l2, |
|
|
c, |
|
|
n |
|
) |
|
|
|
Value: { \
c+=n; \
switch (n) { \
case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
} \
}
Definition at line 296 of file des.c. |
|
Value: (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff))
Definition at line 288 of file des.c. |
#define LOAD_DATA |
( |
R, |
|
|
S, |
|
|
u, |
|
|
t, |
|
|
E0, |
|
|
E1, |
|
|
tmp |
|
) |
|
|
|
Value:
Definition at line 321 of file des.c. |
#define LOAD_DATA_tmp |
( |
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f |
|
) |
LOAD_DATA(a,b,c,d,e,f,g)
|
|
|
Value:
Definition at line 281 of file des.c. |
#define PERM_OP |
( |
a, |
|
|
b, |
|
|
t, |
|
|
n, |
|
|
m |
|
) |
|
|
|
Value: ((t)=((((a)>>(n))^(b))&(m)),\
(b)^=(t),\
(a)^=((t)<<(n)))
Definition at line 379 of file des.c. |
#define ROTATE |
( |
a, |
|
|
n |
|
) |
(((a)>>(n))+((a)<<(32-(n))))
|
|
Function Documentation
void cipher_3des_cbc |
( |
unsigned char * |
text, |
|
|
int |
text_len, |
|
|
unsigned char * |
key, |
|
|
unsigned char * |
iv, |
|
|
int |
mode, |
|
|
unsigned char * |
output |
|
) |
|
|
|
3DES-CBC function calculates a digest from a given data buffer and a given key.
- Parameters:
-
text | pointer to input data |
text_len | length of input data |
key | pointer to encryption key (192 bits) |
iv | initialization vector |
mode | defines whether encryption or decryption should be performed |
output | en- or decrypted input data |
- Returns:
- void
Definition at line 1067 of file des.c. |
void DES_cbc_encrypt |
( |
const unsigned char * |
input, |
|
|
unsigned char * |
output, |
|
|
long |
length, |
|
|
DES_key_schedule * |
schedule, |
|
|
DES_cblock * |
ivec, |
|
|
int |
enc |
|
) |
|
|
void DES_ncbc_encrypt |
( |
const unsigned char * |
input, |
|
|
unsigned char * |
output, |
|
|
long |
length, |
|
|
DES_key_schedule * |
schedule, |
|
|
DES_cblock * |
ivec, |
|
|
int |
enc |
|
) |
|
|
Variable Documentation
const DES_LONG des_skb[8][64] [static]
|
|
|
Definition at line 61 of file des.c. |
|
Initial value: {
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254}
Definition at line 725 of file des.c. |
|
Initial value: {
{0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
{0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
{0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
{0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
{0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
{0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
{0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
{0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
{0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
{0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
{0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
{0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
{0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
{0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
{0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
{0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}
Definition at line 773 of file des.c. |
|