The friendly Operating System for the Internet of Things
3des.h File Reference

Headers for the implementation of the 3DES cipher-algorithm. More...

Detailed Description

Author
Freie Universitaet Berlin, Computer Systems & Telematics,
Nicolai Schmittberger (nicol.nosp@m.ai.s.nosp@m.chmit.nosp@m.tber.nosp@m.ger@f.nosp@m.u-be.nosp@m.rlin..nosp@m.de)
Zakaria Kasmi zkasm.nosp@m.i@in.nosp@m.f.fu-.nosp@m.berl.nosp@m.in.de

Definition in file 3des.h.

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "crypto/ciphers.h"
+ Include dependency graph for 3des.h:

Go to the source code of this file.

#define THREEDES_BLOCK_SIZE   8
 
#define THREEDES_MAX_KEY_SIZE   24
 
#define ROLc(x, y)
 
#define RORc(x, y)
 
#define WPA_GET_BE32(a)
 
#define WPA_PUT_BE32(a, val)
 
static const uint32_t bytebit [8] = {0200, 0100, 040, 020, 010, 04, 02, 01}
 
static const uint32_t bigbyte [24]
 
int tripledes_init (cipher_context_t *context, const uint8_t *key, uint8_t keySize)
 initializes the 3DES Cipher-algorithm with the passed parameters More...
 
int tripledes_encrypt (const cipher_context_t *context, const uint8_t *plain, uint8_t *crypt)
 encrypts one plain-block and saves the result in crypt. More...
 
int tripledes_decrypt (const cipher_context_t *context, const uint8_t *crypt, uint8_t *plain)
 decrypts one cipher-block and saves the plain-block in plain. More...
 

Macro Definition Documentation

#define ROLc (   x,
 
)
Value:
((((unsigned long) (x) << (unsigned long) ((y) & 31)) | \
(((unsigned long) (x) & 0xFFFFFFFFUL) >> \
(unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)

Definition at line 39 of file 3des.h.

#define RORc (   x,
 
)
Value:
(((((unsigned long) (x) & 0xFFFFFFFFUL) >> \
(unsigned long) ((y) & 31)) | \
((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & \
0xFFFFFFFFUL)

Definition at line 44 of file 3des.h.

#define WPA_GET_BE32 (   a)
Value:
((((uint32_t) (a)[0]) << 24) | \
(((uint32_t) (a)[1]) << 16) | \
(((uint32_t) (a)[2]) << 8 ) | ((uint32_t) (a)[3]))

Definition at line 51 of file 3des.h.

#define WPA_PUT_BE32 (   a,
  val 
)
Value:
do { \
(a)[0] = (uint8_t) ((((uint32_t) (val)) >> 24) & 0xff); \
(a)[1] = (uint8_t) ((((uint32_t) (val)) >> 16) & 0xff); \
(a)[2] = (uint8_t) ((((uint32_t) (val)) >> 8) & 0xff); \
(a)[3] = (uint8_t) (((uint32_t) (val)) & 0xff); \
} while (0)

Definition at line 57 of file 3des.h.

Function Documentation

int tripledes_decrypt ( const cipher_context_t context,
const uint8_t *  crypt,
uint8_t *  plain 
)

decrypts one blocksize long block of ciphertext pointed to by crypt to one blocksize long block of plaintext and stores the plaintext in the memory-area pointed to by plain

Parameters
contextthe cipher_context_t-struct to use for this decryption
crypta pointer to the ciphertext-block (of size blocksize) to be decrypted
plaina pointer to the place where the decrypted plaintext will be stored
Returns
-1 if no space for the key could be malloced -2 if the key could not be setup correctly 1 if decryption was successful
int tripledes_encrypt ( const cipher_context_t context,
const uint8_t *  plain,
uint8_t *  crypt 
)

encrypts one blocksize long block of plaintext pointed to by plain to one blocksize long block of ciphertext which will be written to the the memory-area pointed to by crypt

Parameters
contextthe cipher_context_t-struct to use for this encryption
plaina pointer to the plaintext-block (of size blocksize)
crypta pointer to the place where the ciphertext will be stored
Returns
-1 if no space for the key could be malloced -2 if the key could not be setup correctly 1 if encryption was successful
int tripledes_init ( cipher_context_t context,
const uint8_t *  key,
uint8_t  keySize 
)
Parameters
contextthe cipher_context_t-struct to save the initialization of the cipher in
keya pointer to the key
keySizethe size of the key
Returns
CIPHER_INIT_SUCCESS if the initialization was successful. The command may be unsuccessful if the key size is not valid. CIPHER_ERR_BAD_CONTEXT_SIZE if CIPHER_MAX_CONTEXT_SIZE has not been defined (which means that the cipher has not been included in the build)

Variable Documentation

const uint32_t bigbyte[24]
static
Initial value:
= {
0x800000UL, 0x400000UL, 0x200000UL, 0x100000UL,
0x80000UL, 0x40000UL, 0x20000UL, 0x10000UL,
0x8000UL, 0x4000UL, 0x2000UL, 0x1000UL,
0x800UL, 0x400UL, 0x200UL, 0x100UL,
0x80UL, 0x40UL, 0x20UL, 0x10UL,
0x8UL, 0x4UL, 0x2UL, 0x1L
}

Definition at line 70 of file 3des.h.