Skip to main content
  • Products
  • Evaluate our Software
  • Downloads
  • Free Utilities
  • Purchase
  • Support
  • About Us
  • Blog
  • Forum
  • Search
    • Contact Us
    • Forum
    • Wiki
    • Web Shop
    • Newsletter
    • RSS
  •   Jobs
  •   Videos
  •   Blog
  •   Sustainability
  • emLib
  • DES
  • Variations
emlib-des-product-icon

emLib DES – Encrypt & Decrypt Data Files with DES

The emLib DES module allows encryption and dycryption of data using DES, the Data Encryption Standard as published in 1976. This chapter describes the DES API functions and shows their usage based on example code.

  1. 1.What is DES?
  2. 2.Using emLib DES
  3. 3.DES API Functions
  4. 4.Example Code
  5. 5.Sample Applications
  6. 6.Performance and Memory Footprint

What is DES?

The Data Encryption Standard, short DES, is a symmetric-key algorithm for en- and decryption of data. It was developed in the 1970's and established as a standard for the United States by the National Bureau of Standards (NBS, now NIST). DES has been superseded by AES.

DES is a block cypher, taking a fixed-length block of data (64 bits). The key used for processing consists of 64 bits, where only 56 are actually used for transformations and 8 bits are used for parity checks.

DES performs an initial permitation of the data, 16 rounds of transformation, and a final permitation, the inverse of the initial permutation. In the transformations the data block is initially splitted in two 32 bit blocks where the first block is transformated with the round key using a Feistel cipher and XOR-linked with the second block. The first block and the resulting block are used for the next round.

emLib DES uses a key of 64 bits to encrypt a block of 68 bits of data at a time. To optimize the performance of the algorithms the generation of the round keys can be done before the actual encryption or decryption and used more than one time. DES can also be used in cipher block chaining (CBC) mode to process more than 64 bits.

In CBC mode every chunk of 64 bits is XOR linked with the result of the previous encryption (the cipher text), before being encrypted. To decrypt one block, all previous blocks have to be known.

For the encryption of the first block an initialization vector which will be linked with the block, can be used to make sure the first block cannot be brute-force decrypted by comparing it to common first data blocks.

Using emLib DES

The emLib DES module has a simple yet powerful API. It can be easily integrated into an existing application. The code is completely written in ANSI-C.

All functionality can be verified with standard test patterns using the Validation API functions. The functions for generating the tables used for higher optimization levels are also included for full transparency. To simply encrypt or decrypt data the application would only need to call one function.

If more than one block needs to be processed with the same key, a context containing the round keys calculated from the key can be prepared and directly used by the encryption and decryption functions. For more than one call of these functions this method results in a slightly higher processing speed.

DES API Functions

The table below lists the available DES API functions.

FunctionDescription
DES_CBC_Encrypt()Encrypts data with DES using CBC.
DES_CBC_Decrypt()Decrypts data with DES using CBC.
DES_Decrypt()Decrypts 8 Bytes with DES.
DES_Encrypt()Encrypts 8 Bytes with DES.
DES_Prepare()Prepares the context for de-/encryption.
DES_Validate()Test function for validation of DES.

Detailed descriptions of all functions can be found in the emLib user manual.

Example Code

DES en-/decryption of 16 Bytes using CBC

#include <DES.h>
int main(void) {
  DES_CONTEXT Context;
  const U8  aKey[8]        = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
  const U8  aPlain[16]     = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xE7,
                              0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xE7};
        U8  aRefPlain[16];
        U8  aCipher[16];
        int r;
  //
  // Prepare the DES Context with aKey
  //
  DES_PrepareKey(&Context, &aKey[0]);
  //
  // Encrypt the data of aPlain
  //
  DES_CBC_Encrypt(&Context, &aCipher[0], &aPlain[0], sizeof(aPlain), NULL);
  //
  // Decrypt the data of aCipher
  //
  DES_CBC_Decrypt(&Context, &aRefPlain[0], &aCipher[0], sizeof(aCipher), NULL);
  r = memcmp(&aPlain[0], &aRefPlain[0], sizeof(aRefPlain));
  if (r != 0) {
    return -2;
  }
  return r; // DES works fine.
}#include <DES.h>

Sample Applications

emLib includes some sample applications to show the modules functionality and provide an easy to use starting point for your application. The application's source code is included within the module. The following applications are included in emLib DES:

 

Application nameTarget platformDescription
DESSpeedtest.exeWindowsConsole application testing the speed of emLib DES.
DESValidate.exeWindowsConsole application validating emLib DES with standard test patterns.

 

Download emLib DES sample applications

DESSpeedTest

DESSpeedtest is a windows application, testing the performance of the emLib DES algorithms.

emLib_DESSpeed_Screen

DESValidate

DESValidate is a Windows application used to test and validate the implementation of the DES algorithms. The application uses the Validation API and compares the results of encryption and decryption with the expected results. DESValidate will show an error message, if a validation test fails.

Performance and Memory Footprint

emLib DES aims for portability and is designed to fit speed and size requirements for different targets.

Performance test

The performance and memory footprint have been tested on a Cortex-M4 running at 200 MHz from internal flash, using internal RAM.

Results

The following table shows the en- and decryption speed of emLib DES:

 

Compiler optionsSpeed1ROM usage1
Optimize high for speed1.0 MB/s3.2 KB
Optimize high for size0.7 MB/s3.0 KB

1: Results may vary depening on the compiler, compiler settings and memory timings of the microcontroller used.

More Information

Purchase

  • Pricing

Variations

  • AES
  • DES
  • CRC
  • ECC

About us

  • The Company
  • Partners
  • Job Offers
  • Media
  • Contact us

Support

  • Technical Support
  • Blog
  • Forum
  • Wiki

Downloads

  • Application Notes
  • Embedded Studio
  • embOS
  • emCompress
  • emCrypt
  • emFile
  • emLib
  • emLoad
  • emModbus
  • emNet
  • emPower
  • emSecure
  • emSSH
  • emSSL
  • emUSB-Device
  • emUSB-Host
  • emVNC
  • emWin
  • Flasher
  • Free Utilities
  • IoT
  • J-Link / J-Trace
  • Linux Studio
  • SystemView
  • CE / REACH

Social Media

Headquarters

SEGGER Microcontroller GmbH

Ecolab-Allee 5
40789 Monheim am Rhein, Germany
info@segger.com
Tel.: +49-2173-99312-0
Fax: +49-2173-99312-28

Locations

USA: SEGGER Microcontroller Systems LLC

Boston area
101 Suffolk Lane
Gardner, MA 01440, USA
us-east@segger.com
Tel.: +1-978-874-0299
Fax: +1-978-874-0599

Silicon Valley
Milpitas, CA 95035, USA
us-west@segger.com
Tel.: +1-408-767-4068

China: SEGGER Microcontroller China Co., Ltd.

Room 218, Block A, Dahongqiaoguoji
No. 133 Xiulian Road
Minhang District, Shanghai 201199, China
china@segger.com
Tel.: +86-133-619-907-60

ISO 9001 certified

ISO 9001

30+ years of experience

First-class embedded software tools since 1992
  • Imprint
  • Disclaimer
  • Privacy Policy

© 2023 SEGGER - All rights reserved.