| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "common.h" |
| 28 |
#include "block_base.h" |
| 29 |
|
| 30 |
#ifndef PCT_DES3_MODULE |
| 31 |
FAKE_INIT(raw_des) |
| 32 |
#else |
| 33 |
FAKE_INIT(raw_des3) |
| 34 |
#endif |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#define ARGTYPE 4 |
| 39 |
|
| 40 |
|
| 41 |
#define LTC_NO_PROTOTYPES |
| 42 |
#include "libtom/tomcrypt_des.c" |
| 43 |
|
| 44 |
struct block_state { |
| 45 |
symmetric_key sk; |
| 46 |
}; |
| 47 |
|
| 48 |
static int block_init(struct block_state *self, const uint8_t *key, size_t keylen) |
| 49 |
{ |
| 50 |
int rc; |
| 51 |
#ifdef PCT_DES3_MODULE |
| 52 |
rc = des3_setup(key, keylen, 0, &self->sk); |
| 53 |
#else |
| 54 |
rc = des_setup(key, keylen, 0, &self->sk); |
| 55 |
#endif |
| 56 |
switch (rc) { |
| 57 |
case CRYPT_OK: |
| 58 |
return 0; |
| 59 |
case CRYPT_INVALID_KEYSIZE: |
| 60 |
return ERR_KEY_SIZE; |
| 61 |
case CRYPT_INVALID_ROUNDS: |
| 62 |
return ERR_NR_ROUNDS; |
| 63 |
case CRYPT_INVALID_ARG: |
| 64 |
return ERR_UNKNOWN; |
| 65 |
} |
| 66 |
return ERR_UNKNOWN; |
| 67 |
} |
| 68 |
|
| 69 |
static void block_finalize(struct block_state *self) |
| 70 |
{ |
| 71 |
} |
| 72 |
|
| 73 |
static void block_encrypt(struct block_state *self, const uint8_t *in, uint8_t *out) |
| 74 |
{ |
| 75 |
#ifdef PCT_DES3_MODULE |
| 76 |
des3_ecb_encrypt(in, out, &self->sk); |
| 77 |
#else |
| 78 |
des_ecb_encrypt(in, out, &self->sk); |
| 79 |
#endif |
| 80 |
} |
| 81 |
|
| 82 |
static void block_decrypt(struct block_state *self, const uint8_t *in, uint8_t *out) |
| 83 |
{ |
| 84 |
#ifdef PCT_DES3_MODULE |
| 85 |
des3_ecb_decrypt(in, out, &self->sk); |
| 86 |
#else |
| 87 |
des_ecb_decrypt(in, out, &self->sk); |
| 88 |
#endif |
| 89 |
} |
| 90 |
|
| 91 |
#ifdef PCT_DES3_MODULE |
| 92 |
# define MODULE_NAME DES3 |
| 93 |
# define BLOCK_SIZE 8 |
| 94 |
# define KEY_SIZE 0 |
| 95 |
#else |
| 96 |
# define MODULE_NAME DES |
| 97 |
# define BLOCK_SIZE 8 |
| 98 |
# define KEY_SIZE 8 |
| 99 |
#endif |
| 100 |
#include "block_common.c" |