Home

Documentation

image

Contents

1. Table 3 8 Performance test configuration Results The following table shows the en and decryption speed of emLib DES Compiler options Speed ROM usage Optimize high for speed 0 8 MByte sec 3 2 KBytes Optimize high for size 0 6 MByte sec 3 0 KBytes The performance depends on the MCU speed and the flash memory speed Results may vary if a different setup is used UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG Index 51 A AES A DE tb 12 C CBE il A ne end 36 GCiphertext sion en rm EE 12 D DES AA En SR RENE RAS 36 F Feistel cipher cccecceseeeseeseeseeeeeeeaeeaaes 36 I Initialization Vector coocccocccconccconccannncos 12 S Syntax conventions used 5 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 52 Index UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG Index 53 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG
2. This sample shows how to encrypt and afterwards decrypt 32 bytes of data with AES and a 256 bit key using Cipher Block Chaining include AES h const U8 _akKey 32 0x00 0x01 0x02 0x03 0x04 0x08 0x09 Ox0a Ox0b 0x0c 0x10 0x11 0x12 0x13 0x14 0x18 0x19 Oxla Oxlb Oxlc static const U8 _alIv 16 Il ma 0x56 Ox2e 0x17 0x99 0x6d Oxdd 0xb3 Oxba 0x69 Ox5a static const U8 _aPlaintext 32 0x00 0x01 0x02 0x03 0x04 0x08 0x09 0x0a 0x0b 0x0c 0x10 0x11 0x12 0x13 0x14 0x18 0x19 Oxla Oxlb Oxlc int main U8 aEnc 32 U8 aPlain 32 AES_CONTEXT Context Prepare the context with _aKey AES256_Prepare amp Context amp _aKey 0 Encrypt the data of _aPlaintext AES256_CBC_Encrypt amp Context amp aEnc 0 amp _aPlaintext 0 32 amp _aIV 0 Decrypt the data of aEnc and compare it with the previously used _aPlaintext 0x05 0x04 0x15 0x1d 0x09 Ox2e 0x05 0x0d 0x15 0x1d AES256_CBC_Decrypt Context amp aPlain 0 amp aEnc 0 32 amp _aIV 0 if memcmp amp aPlain 0 amp _aPlaintext 0 32 return 1 return 0 AES 256 CBC works fine UM12001 User amp Reference Guide for emLib 0x06 0x0e 0x16 Oxle 0x34 Ox6f 0x06 0x0e 0x16 Oxle 29 0x07 Ox0f 0x17 Ox1f 0x28 0x58 0x07 OxOf 0x17 Ox1f 2013 SEGGER Microcontr
3. Contact address SEGGER Microcontroller GmbH amp Co KG In den Weiden 11 D 40721 Hilden Germany Tel 49 2103 2878 0 Fax 49 2103 2878 28 E mail support segger com Internet http www segger com UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG Manual versions This manual describes the current software version If any error occurs inform us and we will try to assist you as soon as possible Contact us for further information on topics or routines not yet specified Print date July 17 2013 Software Revision Date By Description 1 00 0 130321 JL Initial release UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG About this document Assumptions This document assumes that you already have a solid knowledge of the following e The software tools used for building your application assembler linker C com piler e The C programming language e The target processor e DOS command line If you feel that your knowledge of C is not sufficient we recommend The C Program ming Language by Kernighan and Richie ISBN 0 13 1103628 which describes the standard in C programming and in newer editions also covers the ANSI C standard How to use this manual This manual explains all the functions and macro
4. Table 2 6 AES256_Encrypt parameter list Additional information The data which will be encrypted has to be 16 Bytes For more than 16 Bytes see AES256_CBC_Encrypt on page 23 Example See AES 256bit en decryption of 16 Bytes on page 28 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 20 CHAPTER 2 AES 2 3 6 AES256_Decrypt Description Decrypts a block of 16 Bytes 128 bit using a context prepared with the 256 bit key Prototype void AES128 Decrypt AES CONTEXT pContext U8 pDest const U8 pSrc Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the decrypted data pSrc Pointer to the buffer which holds the encrypted data Table 2 7 AES256_Decrypt parameter list Additional information The key has to be the same as the one used for encryption The data which will be decrypted has to be 16 Bytes For more than 16 Bytes see AES256_CBC_Decrypt on page 24 Example See AES 256bit en decryption of 16 Bytes on page 28 UM12001 User amp Reference Guide for emLib O 2013 SEGGER Microcontroller GmbH Co KG 21 2 3 7 AES128_CBC_Encrypt Description Encrypts data using cypher block chaining and a 128 bit key Prototype void AES128_CBC_Encrypt AES_CONTEXT pContext U8 pDest const U8 pSrc int NumBytes const U8 pIV P
5. IAR EWARM V6 40E Table 2 15 Performance test configuration Results The following table shows the en and decryption speed of emLib AES128 Compiler options Module defines Speed ROM usage Optimize high for speed OPT OPT IMIZE_MIX_SUBST IMIZE MIX COLUMNS 2 PACS MByte sec 11 8 KBytes Optimize high for size OPT OPT IMIZE_MIX_SUBST IMIZE MIX COLUMNS 0 0 0 4 MByte sec 3 4 KBytes The performance depends on UM12001 User amp Reference Guide for emLib the MCU speed and the flash memory speed Results may vary if a different setup is used 2013 SEGGER Microcontroller GmbH amp Co KG 35 Chapter 3 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 func tions and shows their usage based on example codes In this chapter you will find a description of the DES module API functions and sam ples for their implementation UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 36 CHAPTER 3 DES 3 1 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 i
6. Number of Bytes which has to be encrypted pIV optional Initialization vector for the first block of data Table 3 5 DES_CBC_Encrypt parameter list Additional information The data has to be a multiple of 8 Byte To prepare the context use DES_Prepare If pIV is NULL an initialization vector of O is used Example See DES en decryption of 16 Bytes using CBC on page 46 UM12001 User amp Reference Guide for emLib O 2013 SEGGER Microcontroller GmbH Co KG 43 3 3 5 DES CBC_Decrypt Description Decrypts a data block using DES with cypher block chaining Prototype void DES_CBC_Decrypt DES_CONTEXT pContext U8 pDest const U8 pSrc int NumBytes const U8 pIV Parameter Description pContext Pointer to the DES context pDest Pointer to the buffer for the decrypted data pSrc Pointer to the buffer with encrypted data NumBytes Number of Bytes which has to be decrypted pIV optional Initialization vector used for the first data block Table 3 6 DES_CBC_Decrypt parameter list Additional information The context has to be generated with the same key as for encryption The initializa tion vector has to be the same as for encryption If pIV is NULL an initialization vector of O is used The data has to be a multiple of 8 Bytes Example See DES en decryption of 16 Bytes using CBC on page 46 UM12001 User amp Reference Guide for emLib 20
7. amp Co KG 46 CHAPTER 3 DES 3 4 2 DES en decryption of 16 Bytes using CBC include lt DES h gt int main void DES_CONTEXT Context const U8 aKey 8 0x01 0x23 0x45 0x67 0x89 OxAB OxCD OxEF const U8 aPlain 16 0x01 0x23 0x45 0x67 0x89 OxAB OxCD OxE7 0x01 0x23 0x45 0x67 0x89 OxAB OxCD 0xE7 U8 aRefPlain 16 U8 aCipher 16 int r Prepare the DES Context with aKey EL DES_PrepareKey amp Context amp aKey 0 Encrypt the data of aPlain DES_CBC_Encrypt amp Context amp aCipher 0 amp aPlain 0 sizeof aPlain NULL Decrypt the data of aCipher DES_CBC_Decrypt amp Context amp aRefPlain 0 amp aCipher 0 sizeof aCipher NULL r amp aRefPlain 0 if memcmp amp aPlain 0 r 0 return 2 return Y DES works fine UM12001 User amp Reference Guide for emLib sizeof aRefPlain 2013 SEGGER Microcontroller GmbH amp Co KG 47 3 5 Sample applications emLib includes some sample applications to show the modules functionality and pro vide 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 name Target platform Description 7 Console application testing the speed of DESSpeedtest exe Windows emLib DES Console application validating emLib DES with standard test pat
8. 13 SEGGER Microcontroller GmbH amp Co KG 44 CHAPTER 3 DES 3 3 6 DES Validate Description This function is used to test the DES implementation It uses defined plain data and a defined key for encryption and checks if the encryp tion result is correct The initialization vector is 0 Prototype int DES Validate void Return values 0 O K No error 1 Error Encryption failed The implementation is not working correctly 2 Error Decryption failed The implementation is not working correctly Additional information Validation set from NIST special publication 800 17 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 45 3 4 Example codes 3 4 1 DES en decryption of 8 Bytes include lt DES h gt int main void DES_CONTEXT Context const U8 aKey 8 const U8 aPlain 8 U8 aRefPlain 8 U8 aCipher 8 0x01 0x23 0x45 0x67 0x89 OxAB OxCD OxEF 0x01 0x23 0x45 0x67 0x89 OxAB OxCD 0xE7 int r Prepare the DES Context with aKey E E N ne amp aKey 0 iy Encrypt the data of aPlain Be etek ene gees tac amp aCipher 0 amp aPlain 0 7 Decrypt the data of aCipher PR ous amp aRefPlain 0 amp aCipher 0 r memcmp amp aPlain 0 amp aRefPlain 0 sizeof aRefPlain if r 0 A return 2 return r DES works fine UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH
9. 6 16MB 84 13MB 13MB7s AES testing the performance of the emLib AES IDone JDone Done Done 2013 SEGGER Microcontroller GmbH amp Co KG 33 2 5 3 AESValidate AESValidate is a Windows application used to test and validate the implementation of the AES algorithms The application uses the Validation API and compares the results of encryption and decryption with the expected results AESValidate will show an error message if a validation test fails UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 34 CHAPTER 2 2 6 Performance and memory footprint emLib AES aims for portability and is designed to fit speed and size requirements for different targets AES It includes configurable defines to switch between speed and size optimizations The values can be changed in AES_Config h define Values Description OPTIMIZE_MIX_SUBST OPTIMIZE_MIX_COLUMNS O No opt Use a 32 bit table to perform MixCol 1 default umns and SubBytes at the same time O default 1 2 highest Use tables for matrix multiplication Table 2 14 Optimization defines 2 6 1 Performance test The following system has been used to measure the performance and memory foot print of the module with different optimization levels Detail Description Target STM32F417 running at 168 MHz internal flash used Tool chain
10. AESSpeedtest inicia ii 32 2 5 3 AES Validate iso rta a AA AA 33 2 6 Performance and Memory footprint sis 34 2 6 1 Performance testi a it Ie 34 IDE is 35 3 1 Whats DESTA A a 36 3 2 Usindsemlib DES is e a ea a Bele eke ne E cS 37 3 3 DES API FUNCHONS cid ann eme csvset as 38 3 4 EXAMPLE GOd CS ii A etree anaes ATA AS A 45 3 5 Sample applications ic e ad 47 3 5 1 DESSpeedtest resco crete o e wad 48 3 5 2 DES Valiclate test sit a5 Sek moa Melek ha Aden SEE es snide ase cae RAN 49 3 6 Performance and Memory footprint sis 50 3 6 1 Performance test s A AAA Te 50 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG Chapter 1 Introduction to emLib This chapter provides an introduction to emLib It explains the basic concept behind emLib and its modules UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 10 CHAPTER 1 Introduction to emLib 1 1 What is emLib emLib is a collection of software modules for different purposes It currently includes AES and DES encryption Modules for CRC compression and aysmmetric encryption decryption are planned The software is designed for portability to any device The modules can be used in PC applications as well as on embedded target devices emLib is optimized for speed performance and a sma
11. S_Validate Test function for validation of DES Table 3 1 DES API function overview UM12001 User amp Reference Guide for emLib O 2013 SEGGER Microcontroller GmbH Co KG 39 3 3 1 DES Prepare Description Prepares the context depending on the 64bit key used for DES de encryption Prototype void DES_Prepare DES_CONTEXT pContext const U8 pKey Parameter Description pContext Pointer to the context for de encryption pKey Pointer to the buffer which holds the encryption key 64bit Table 3 2 DES_Prepare parameter list Additional information The key has 1 parity bit per byte so the effective key length is 56bit A pointer to a 64bit key has to be provided to the function Example See DES en decryption of 8 Bytes on page 45 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 40 CHAPTER 3 3 3 2 DES Encrypt DES Description Encrypts a block of 8 Bytes 64 bit using a context prepared with the 64 bit key Prototype void DES Encrypt DES CONTEXT pContext U8 pDest const U8 pSrc Parameter Description pContext Pointer to the prepared context for DES encryption pDest Pointer to the buffer for the encrypted data pSre Pointer to the plain text data buffer which has to be encrypted Table 3 3 DES_Encrypt parameter list Additional information The data has to be 64bit For m
12. Usind 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 and MISRA C compliant 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 func tion If more than one block needs to be processed with the same key a context con taining 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 The following section lists and describes the available API functions of the emLib DES module UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 38 3 3 DES API functions CHAPTER 3 DES The table below lists the available API functions Function Description DES_CBC_Enerypt Encrypts data with DES using CBC DES_CBC_Decrypt Decrypts data with DES using CBC Decrypts 8 Bytes with DES DES Encrypt Encrypts 8 Bytes with DES D D DES Decrypt D D DES Prepare Prepares the context for de encryption E
13. arameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the encrypted data pSre Pointer to the buffer which holds the data NumBytes Number of Bytes which have to be encrypted pIV Pointer to the buffer which holds the initialization verctor Table 2 8 AES128_CBC_Encrypt parameter list Additional information The length of the data has to be a multiple of 16 bytes If pIV is NULL the first block will not be linked pDest and pSrc may be the same if the plain data is not needed after encryption Example See AES 128bit en decryption of 32 Bytes using CBC on page 27 UM12001 User amp Reference Guide for emLib O 2013 SEGGER Microcontroller GmbH 8 Co KG 22 CHAPTER 2 AES 2 3 8 AES128 CBC_Decrypt Description Decrypts data using cypher block chaining and a 128 bit key Prototype void AES128_CBC_Decrypt AES_CONTEXT pContext U8 pDest const U8 pSrc int NumBytes const U8 pIV Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the decrypted data pSre Pointer to the buffer which holds the encrypted data NumBytes Number of Bytes which have to be decrypted pIV Pointer to the buffer which holds the initialization verctor Table 2 9 AES128_CBC_Decrypt parameter list Additional information The key and the initialization vector ha
14. ck Chaining include AES h const U8 _aKey 16 Oxc2 0x86 0x69 Ox6d 0x88 Ox7c 0x9a 0x61 Oxlb Oxbb Ox3e 0x20 0x25 Oxa4 static const U8 _alIv 16 Il ma 0x56 Ox2e 0x17 0x99 Ox6d 0x09 0x3d Oxdd Oxb3 Oxba 0x69 Ox5a Ox2e Ox6f static const U8 _aPlaintext 32 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x08 0x09 0x0a 0x0b 0x0c Ox0d Ox0e 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x18 0x19 Oxla Oxlb Oxic Oxld Oxle static const U8 _aCiphertext 32 Oxd2 0x96 Oxcd 0x94 Oxc2 Oxcc Oxcf Ox3a 0x86 0x30 0x28 Oxb5 Oxel Oxdc 0x75 0x86 0x60 Ox2d 0x25 Ox3c Oxff Oxlb 0x82 0x66 Oxbe Oxa6 Oxd6 Oxia int main U8 aEnc 32 U8 aPlain 32 AES_CONTEXT Context Prepare the context with _aKey AES128_Prepare amp Context amp _aKey 0 Encrypt the data of _aPlaintext and compare it with the desired result AES128_CBC_Encrypt amp Context amp aEnc 0 amp _aPlaintext 0 32 amp _aIV 0 if memcmp amp aEnc 0 amp _aCiphertext 0 32 return 1 Decrypt the data of aEnc and compare it with the previously used _aPlaintext AES128_CBC_Decrypt amp Context amp aPlain 0 amp aEnc 0 32 amp _aIV 0 if memcmp amp aPlain 0 amp _aPlaintext 0 32 return 1 return 0 AES 128 CBC works fine Oxad Ox5a 0x28 0x58 0x07 OxOf 0x17 Ox1f Ox8a 0x0a O
15. drivers e g for NAND and NOR flashes SD MMC and Compact Flash cards are available USB Stack USB device host stack A USB stack designed to work on any embedded system with a USB control ler Bulk communication and most stan dard device classes are supported fi UM12001 User amp Reference Guide for SEGGER TOOLS Flasher Flash programmer Flash Programming tool primarily for micro con trollers J Link JTAG emulator for ARM cores USB driven JTAG interface for ARM cores J Trace JTAG emulator with trace USB driven JTAG interface for ARM cores with Trace memory supporting the ARM ETM Embed ded Trace Macrocell J Link J Trace Related Software Add on software to be used with SEGGER s indus try standard JTAG emulator this includes flash programming software and flash breakpoints 2013 SEGGER Microcontroller GmbH amp Co KG Table of Contents 1 Introduction to A la A RS PA a ee ai Nath hoe ahaa Aa 9 1 1 Whats embibiini din diana 10 1 2 EU A a o 10 1 3 AVailabl modules en mn te E Na 10 1 3 1 Cryptographic modules EE ERR ERR REEL RE EE ERE EE EES 10 TEI AN coho ee eRe Fae EN eee REO er ee ee re eo ne Pee ere Senay Se 11 2 1 What is AES a A ia 12 2 2 USING EMLID AES issue part evened sca O ent veaudas Lad A O 13 2 3 AES APD UA tions iria as ia 14 2 4 Example Codes sie ne PRET Re A A A AAA 26 2 5 Sample application Sa ii ir 30 2 5 1 AES Cry 2 cada A AA shiv A idee 31 2 5 2
16. emLib 2013 SEGGER Microcontroller GmbH amp Co KG 14 2 3 AES API functions CHAPTER 2 AES The table below lists the available API functions Function Description AES128_CBC_Decrypt Decrypts data with AES 128 Bit using CBC AES128_CBC_Encrypt Encrypts data with AES 128 Bit using CBC AES128_Decrypt Decrypts 16 Bytes with AES 128 Bit AES128_Encrypt Encrypts 16 Bytes with AES 128 Bit AES128_Prepare Prepares the context for de encryption AES256_CBC_Decrypt Decrypts data with AES 256 Bit using CBC AES256_CBC_Encrypt Encrypts data with AES 256 Bit using CBC AES256_Decrypt Decrypts 16 Bytes with AES 256 Bit AES256_Encrypt Encrypts 16 Bytes with AES 256 Bit AES256_Prepare Prepares the context for de encryption AES_Validate Test function for validation of AES Table 2 1 AES API function overview UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 2 3 1 AES128_Prepare Description Prepares the context depending on the key used for AES 128bit de encryption Prototype void AES128 Prepare AES_CONTEXT pContext const U8 pKey Parameter Description pContext Pointer to the context for de encryption pKey Pointer to the buffer which holds the encryption key 128bit Table 2 2 AES128_Prepare parameter list Additional infor
17. emLib Library collection User amp Reference Guide Document UM12001 Software version 1 0 Revision 0 Date July 17 2013 gt SEGGER A product of SEGGER Microcontroller GmbH amp Co KG www segger com Disclaimer Specifications written in this document are believed to be accurate but are not guar anteed to be entirely free of error The information in this manual is subject to change for functional or performance improvements without notice Please make sure your manual is the latest edition While the information herein is assumed to be accurate SEGGER Microcontroller GmbH amp Co KG SEGGER assumes no responsibil ity for any errors or omissions SEGGER makes and you receive no warranties or con ditions express implied statutory or in any communication with you SEGGER specifically disclaims any implied warranty of merchantability or fitness for a particu lar purpose Copyright notice You may not extract portions of this manual or modify the PDF file in any way without the prior written permission of SEGGER The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license 2013 SEGGER Microcontroller GmbH amp Co KG Hilden Germany Trademarks Names mentioned in this manual may be trademarks of their respective companies Brand and product names are trademarks or registered trademarks of their respec tive holders
18. he file which has to be en decrypted Password used for en decryption optional en Force encryption of the source file de Force decryption of the source file If no option is given operation depends on source file extension Table 2 13 AESCrypt parameter list Additional information The password can contain any character and does not have a fixed required length The output file after encryption will have the extension enc If present the original file will be renamed to lt Filename gt orig when decrypting a file with the same name i Microcontroller GmbH amp Co i egger con AESCrypt V1 B1 compiled Jul 17 2813 11 46 24 Please enter the pa word SEGGER enLibAES File encry pt 10n MReading source file information done Ciitempisample bin 512 8 KByte Generating o file information done Filename Cirtemp Sample bin ent crypt ing file 100x done Processed data 512 4 KBute Encryption time 16 ms Encryption speed 32 886 KB ms any key to continue UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 32 2 5 2 AESSpeedtest AESSpeedtest is a windows application algorithms www seqger con i compiled syption syption ypt ion ypt ion UM12001 User amp Reference Guide for emLib CHAPTER 2 2413 SEGGER Microcontroller GmbH Tren ol 1868 190 a 188 102 46MB 1 4
19. ications and embOS a small yet efficient real time kernel emWin written entirely in ANSI C can easily be used on any CPU and most any display It is comple mented by the available PC tools Bitmap Converter Font Converter Simulator and Viewer embOS supports most 8 16 32 bit CPUs Its small memory footprint makes it suitable for single chip applications Apart from its main focus on software tools SEGGER develops and produces programming tools for flash micro controllers as well as J Link a JTAG emulator to assist in develop ment debugging and production which has rapidly become the industry standard for debug access to ARM cores Corporate Office http www segger com United States Office http www segger us com EMBEDDED SOFTWARE Middleware emWin Graphics software and GUI emWin is designed to provide an effi cient processor and display control ler independent graphical user interface GUI for any application that operates with a graphical display embos Real Time Operating System EX embOS is an RTOS designed to offer TA the benefits of a complete multitasking system for hard real time applications with minimal resources embOS IP TCP IP stack embOS IP a high performance TCP IP stack that has been optimized for speed versatility and a small memory footprint emFile File system emFile is an embedded file system with FS FAT12 FAT16 and FAT32 support Var ious Device
20. ll memory footprint The sources are completely written in ANSI C and MISRA C 2004 compliant Validation code for the APIs using standard test patterns is included 1 2 Features emLib is written in ANSI C and can be used on virtually any CPU Some features of emLib e Easy to integrate by using a simple API e Same modules and same API can be used in PC programs as well as on embed ded targets e Sample applications for tests and validation of the modules included 13 Available modules 1 3 1 Cryptographic modules AES module Implemention of the AES 128 bit and 256 bit algorithm including chained block pro cessing for en decryption of more than 16 Byte of data DES module Implementation of the DES 56 bit algorithm also including CBC for processing more than 8 Byte of data The DES functions can be called multiple times to achieve a higher security TDES tripel DES UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG Chapter 2 AES The emLib AES module allows encryption and decryption of data using AES the Advanced Encryption Standard as standardized by NIST in 2001 This chapter describes the AES API functions and shows their usage based on example codes UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 12 CHAPTER 2 AES 2 1 Whatis AES The Advanced Encryption Standard short AES is a symmetric key algorithm used for e
21. mation The key has to be 128 bit 16 Byte long Example See AES 128bit en decryption of 16 Bytes on page 26 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 16 CHAPTER 2 AES 2 3 2 AES128_Encrypt Description Encrypts a block of 16 Bytes 128 bit using a context prepared with a 128 bit key Prototype void AES128_ Encrypt AES CONTEXT pContext Us pDest const U8 pSrc Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the encrypted data pSre Pointer to the buffer which holds the unencrypted data Table 2 3 AES128_Encrypt parameter list Additional information The data which will be encrypted has to be 16 Bytes For more than 16 Bytes see AES128_CBC_Encrypt on page 21 Example See AES 128bit en decryption of 16 Bytes on page 26 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 2 3 3 AES128_Decrypt Description Decrypts a block of 16 Bytes 128 bit using a context prepared with a 128 bit key Prototype void AES128_ Decrypt AES CONTEXT pContext Us pDest const U8 pSrc Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the decrypted data pSrc Pointer to the buffer which holds the encrypted data Table 2 4 AES128_Decryp
22. ncryption an decryption of data It was established by the U S National Institute of Standards and Technology NIST and is the standard for encrypting electronic data since 2001 AES supersedes the Data Encryption Standard DES AES is a substitution permutation network block cipher using a fixed block size of 128 bits and a key size of 128 192 or 256 bits The data block is stored in a 4 row matrix with a cell size of 8 bits Based on the key length these blocks are transformed using parts of the key in a number of rounds AES 128 uses 10 rounds AES 256 14 Therefore encryption with AES 256 is 40 slower than AES 128 In each round a round key is derived from the original key Afterwards each byte is non linear substituted according to a lookup table the rows of the data matrix are shifted cyclically and mixed emLib AES uses a key of 128 or 256 bits to encrypt a block of 16 bytes 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 For the substitution and mixing steps emLib can be built with pre calculated lookup tables to increase the speed performance emLib can also be built without these tables to save memory AES can also be used in cipher block chaining CBC mode to process a multiple of 16 Bytes In CBC mode every chunk of 16 Bytes is XOR linked with the result of the previous encryption the ciphe
23. oller GmbH amp Co KG 30 CHAPTER 2 AES 2 5 Sample applications emLib includes some sample applications to show the modules functionality and pro vide 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 AES Application name Target platform Description Commandline tool to en decrypt a file AESCrypt exe Windows using AES 256 Console application testing the speed of AESSpeedtest exe Windows emLib AES Console application validating emLib AES AESValidate exe Windows with standard test patterns Table 2 12 Sample Applications UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 31 2 5 1 AESCrypt AESCrypt is a windows application encrypting and decrypting a file with the given keyword The tool can be used to easily keep files secured 2 Microcontroller GmbH amp Co seqger con compiled Jul 17 2813 11 46 24 sourcefile pas word l en de File which has to be en decrypted Password used for for en decryption If none i given AE ypt will ask for it Optional Force encry ion or decryption irrespective of the file extension 3 E ypt Plain txt AESCryptPa word en 2 cfile gt enc ey to continue Usage AESCrypt lt sourcefile gt lt password gt lt option gt Parameter Description Path to t
24. or emLib O 2013 SEGGER Microcontroller GmbH 8 Co KG 26 CHAPTER 2 2 4 Example codes AES 2 4 1 AES 128bit en decryption of 16 Bytes This sample shows how to encrypt and afterwards decrypt 16 bytes of data with AES and a 128 bit key include AES h const U8 _aKey 16 0x00 0x01 0x02 0x08 0x09 Ox0a const U8 _aPlaintext 16 0x00 0x11 0x22 int main U8 aEncrypted 16 U8 aDecrypted 16 AES_CONTEXT Context 0x88 0x99 Oxaa Prepares the AES Context with _aKey AES128_Prepare amp Context amp _aKey 0 0x03 0x04 0x05 0x06 0x07 0x0b 0x0c 0x0d 0x0e 0x0f 0x33 0x44 0x55 0x66 0x77 Oxbb Oxcc Oxdd Oxee Oxff Encrypts the data from _aPlaintext and stores it in aEncrypted AES128_ Encrypt amp Context amp aEncrypted 0 amp _aPlaintext 0 Decrypts the data from aEncrypted and stores it in aDecrypted UA AES128 Decrypt amp Context amp aDecrypted 0 amp aEncrypted 0 Check if aDecrypted is the same as _aPlaintext if memcmp amp aDecrypted 0 return 1 return 0 UM12001 User amp Reference Guide for emLib _aPlaintext 16 A 2013 SEGGER Microcontroller GmbH amp Co KG 2 4 2 AES 128bit en decryption of 32 Bytes using CBC 27 This sample shows how to encrypt and afterwards decrypt 32 bytes of data with AES and a 128 bit key using Cipher Blo
25. ore than 64 bit see DES_CBC_Encrypt Example on page 42 See DES en decryption of 8 Bytes on page 45 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 41 3 3 3 DES Decrypt Description Decrypts a block of 8 Bytes 64 bit using a context prepared with the 64 bit key Prototype void DES_Decrypt DES CONTEXT pContext U8 pDest const U8 pSrc Parameter Description pContext Pointer to the prepared DES conctext pDest Pointer to the buffer for the decrypted data pera Pointer to the buffer with the encrypted data Table 3 4 DES_Decrypt parameter list Additional information The key has to be the same as the one used for encryption The data which will be decrypted has to be 64bit long For more than 64bit see DES CBC Decrypt on page 43 Example See DES en decryption of 8 Bytes on page 45 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 42 CHAPTER 3 DES 3 3 4 DES CBC_Encrypt Description Encrypts a block of data using DES with cypher blcok chaining Prototype void DES_CBC_Encrypt DES_CONTEXT pContext U8 pDest const U8 pSrc int NumBytes const U8 pIV Parameter Description pContext Pointer to the DES context pDest Pointer to the data buffer for the encrypted data pSrc Pointer to the plain data buffer NumBytes
26. r text before being encrypted To decrypt one block all previ ous 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 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 2 2 Using emLib AES The emLib AES module has a simple yet powerful API It can be easily integrated into an existing application The code is completely written in ANSI C and MISRA C compliant 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 The module can be built with configurable optimizations to fit any requirement of high speed or low memory usage To simply encrypt or decrypt data the application would only need to call one func tion If more than one block needs to be processed with the same key a context contain ing 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 The following section lists and describes the available API functions of the emLib AES module UM12001 User amp Reference Guide for
27. s 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 transfor mated 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 previ ous 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 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 37 3 2
28. s that the product offers It assumes you have a working knowledge of the C language Knowledge of assembly program ming is not required Typographic conventions for syntax This manual uses the following typographic conventions Style Used for Body Body text opus Text that you enter at the command prompt or that appears on the display that is system functions file or pathnames Parameter Parameters in API functions Sample Sample code in program examples Sample comment Comments in programm examples Reference to chapters sections tables and figures or other docu Reference ments GUIElement Buttons dialog boxes menu names menu commands Emphasis Very important sections Table 1 1 Typographic conventions UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG SEGGER Microcontroller GmbH amp Co KG develops and distributes software development tools and ANSI C software components middleware for embedded sys tems in several industries such as telecom medical technology consumer electronics automotive industry and industrial automation SEGGER SEGGER s intention is to cut software development time for embedded applications by offering compact flexible and easy to use middleware allowing developers to concentrate on their application Our most popular products are emWin a universal graphic software package for embed ded appl
29. sing cypher block chaining and a 256 bit key Prototype void AES128_CBC_Decrypt AES_CONTEXT pContext U8 pDest const U8 pSrc int NumBytes const U8 pIV Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the decrypted data pSre Pointer to the buffer which holds the encrypted data NumBytes Number of Bytes which have to be decrypted pIV Pointer to the buffer which holds the initialization vector Table 2 11 AES256_CBC_Decrypt parameter list Additional information The key and the initialization vector have to be the same as used for encryption The length of the data has to be a multiple of 16 bytes If pIV is NULL the first block will not be linked pDest and pSrc must be different Example See AES 256bit en decryption of 32 Bytes using CBC on page 29 UM12001 User amp Reference Guide for emLib O 2013 SEGGER Microcontroller GmbH Co KG 25 2 3 11 AES Validate Description This function can be used to test the AES implementation It en and decrypts specified data and checks for valid output Prototype int AES Validate void Return values 0 O K No error lt 0 Error The implementation is not working correctly Additional information The data for the validation is taken from RFC 3062 http www rfc editor org rfc rfc3602 txt Chapter 4 UM12001 User amp Reference Guide f
30. t parameter list Additional information The key has to be the same as the one used for encryption The data which will be decrypted has to be 16 Bytes For more than 16 Bytes see AES128 CBC Decrypt on page 22 Example See AES 128bit en decryption of 16 Bytes on page 26 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 18 CHAPTER 2 AES 2 3 4 AES256_Prepare Description Prepares the context depending on the key used for AES 256bit de encryption Prototype void AES256_Prepare AES CONTEXT pContext const U8 pKey Parameter Description pContext Pointer to the context for de encryption pKey Pointer to the buffer which holds the encryption key 256bit Table 2 5 AES256_Prepare parameter list Additional information The key has to be 256 bit 32 Byte long Example See AES 256bit en decryption of 16 Bytes on page 28 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 2 3 5 AES256_Encrypt Description Encrypts a block of 16 Bytes 128 bit using a context prepared with the 256 bit key Prototype void AES128 Encrypt AES_CONTEXT pContext U8 pDest const U8 pSrc Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the encrypted data pSre Pointer to the buffer which holds the unencrypted data
31. terns DESValidate exe Windows Table 3 7 Sample Applications UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 48 CHAPTER 3 DES 3 5 1 DESSpeedtest DESSpeedtest is a windows application testing the performance of the emLib DES algorithms ocontroller GmbH amp gt encryption performance or 5 iB data 1184 1Done S decryption performance fo MB MB data 188 1Done ims i 732m SAMB 721ms 58MB close this UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 49 3 5 2 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 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 50 CHAPTER 3 DES 3 6 Performance and memory footprint emLib DES aims for portability and is designed to fit speed and size requirements for different targets 3 6 1 Performance test The following system has been used to measure the performance and memory foot print of the module with different optimization levels Detail Description Target STM32F417 running at 168 MHz internal flash used Tool chain IAR EWARM V6 40E
32. ve to be the same as used for encryption The length of the data has to be a multiple of 16 bytes If pIV is NULL the first block will not be linked pDest and pSrc must be different Example See AES 128bit en decryption of 32 Bytes using CBC on page 27 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 2 3 9 AES25 Description 23 6 CBC_Encrypt Encrypts data using cypher block chaining and a 256 bit key Prototype void AES128 CI BC_Encrypt AES CONTEXT pContext U8 pDest const U8 pSrc int Num Bytes const U8 pIV Parameter Description pContext Pointer to the previously prepared context pDest Pointer to the buffer which will hold the encrypted data pSre Pointer to the buffer which holds the data NumBytes Number of Bytes which have to be encrypted pIV Pointer to the buffer which holds the initialization vector Table 2 10 AES256_CBC_Encrypt parameter list Additional information The length of t he data has to be a multiple of 16 bytes If pIV is NULL the first block will not be linked pDest and pSrc may be the same if the plain data is not needed after encryption Example See AES 256bit en decryption of 32 Bytes using CBC on page 29 UM12001 User amp Referenc e Guide for emLib O 2013 SEGGER Microcontroller GmbH 8 Co KG 24 CHAPTER 2 AES 2 3 10 AES256_CBC_Decrypt Description Decrypts data u
33. xf9 0xb1 UM12001 User amp Reference Guide for emLib 2013 SEGGER Microcontroller GmbH amp Co KG 28 CHAPTER 2 2 4 3 AES 256bit en decryption of 16 Bytes This sample shows how to encrypt and afterwards decrypt 16 bytes of data with AES and a 256 bit key include AES h const U8 _aKey 32 0x00 0x01 0x02 0x03 0x08 0x09 Ox0a Ox0b 0x10 0x11 0x12 0x13 0x18 0x19 Oxla Oxlb const U8 _aPlaintext 16 0x00 0x11 0x22 0x88 0x99 Oxaa int main U8 aEncrypted 16 U8 aDecrypted 16 AES_CONTEXT Context Prepares the AES Context with _aKey AES256_Prepare amp Context amp _aKey 0 0x04 0x05 0x06 0x0c 0x0d 0x0e 0x14 0x15 0x16 0x1c Oxld Oxle 0x33 0x44 0x55 Oxbb Oxcc Oxdd AES 0x07 Ox0f 0x17 Ox1lf 0x66 0x77 Oxee Oxff Encrypts the data from _aPlaintext and stores it in aEncrypted AES256_Encrypt amp Context amp aEncrypted 0 amp _aPlaintext 0 Decrypts the data from aEncrypted and stores it in aDecrypted AES256_Decrypt amp Context amp aDecrypted 0 amp aEncrypted 0 Check if aDecrypted is the same as _aPlaintext if memcmp amp aDecrypted 0 _aPlaintext return 1 return 0 UM12001 User amp Reference Guide for emLib 16 2013 SEGGER Microcontroller GmbH amp Co KG 2 4 4 AES 256bit en decryption of 32 Bytes using CBC

Download Pdf Manuals

image

Related Search

Documentation documentation documentation synonym documentation meaning documentation template documentation needed for real id documentation tools documentation control software documentation software documentation images documentation icon documentation fee documentation specialist documentation as code documentation standards documentation specialist jobs documentation python documentation for real id documentation generator documentation html documentation for visual studio code documentation django documentation api documentation unity documentation matlab documentation docker

Related Contents

Trust 18402  Istruzioni per l`uso  10 Grandes Dicas de Fotografia  PLC EVB08 Development Kits User`s manual    ISR BCA  PSYCHORICH添付文書  Fiber_Interferometer 08sii  チャイルドシート安全取り締まりで不合格率70% 25.04.11  DT3 2011_EN - Central Vacuum Solutions  

Copyright © All rights reserved.
Failed to retrieve file