Encryption and decryption

Encryption and decryption — Methods to perform encryption and decryption.

Functions

void dukpt_encrypt ()
void dukpt_decrypt ()

Description

This section defines the methods required to perform encryption and decryption using DUKPT.

Functions

dukpt_encrypt ()

void
dukpt_encrypt (const dukpt_key_t *key,
               const uint8_t *data,
               size_t data_size,
               uint8_t *out,
               size_t out_size);

Encrypt data using key and store it in out .

The size of the output encrypted data will be the same as the input one, and therefore out_size must be at least the same size as data_size .

Example 3. Encrypt and decrypt text using the PIN key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
static const dukpt_ksn_t ksn = {
    0x62, 0x99, 0x49, 0x01, 0x2c,
    0x00, 0x00, 0x00, 0x00, 0x03
};
static const dukpt_key_t ipek = {
    0xd2, 0x94, 0x3c, 0xcf, 0x80, 0xf4, 0x2e, 0x88,
    0xe2, 0x3c, 0x12, 0xd1, 0x16, 0x2f, 0xd5, 0x47
};
static const char *input = "Hello World"

size_t data_size;
dukpt_key_t key;
char encrypted[256];
char decrypted[256];

data_size = strlen (input);

dukpt_compute_key (&ipek, &ksn, DUKPT_KEY_TYPE_PIN_ENCRYPTION, &key);
dukpt_encrypt (&key, (const uint8_t *) input, data_size, (uint8_t *) encrypted_text, sizeof (encrypted));
dukpt_decrypt (&key, (const uint8_t *) encrypted, data_size, (uint8_t *) decrypted, sizeof (decrypted));

if (memcmp (input, decrypted, data_size) == 0) {
    printf ("Correct encryption/decryption process\n");
}

Parameters

key

a dukpt_key_t.

 

data

location of the input data to encrypt.

 

data_size

size of data .

 

out

output location where to store the encrypted data.

 

out_size

size of out .

 

dukpt_decrypt ()

void
dukpt_decrypt (const dukpt_key_t *key,
               const uint8_t *data,
               size_t data_size,
               uint8_t *out,
               size_t out_size);

Decrypt data using key and store it in out .

The size of the output decrypted data will be the same as the input encrypted one, and therefore out_size must be at least the same size as data_size .

See dukpt_encrypt() for an example on how to use this method.

Parameters

key

a dukpt_key_t.

 

data

location of the input data to decrypt.

 

data_size

size of data .

 

out

output location where to store the decrypted data.

 

out_size

size of out .

 

Types and Values