1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2013, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
30 /** \addtogroup tdes_module Working with TDES
\r
31 * \ingroup peripherals_module
\r
32 * The ADC driver provides the interface to configure and use the TDES peripheral.
\r
35 * The Data Encryption Standard (DES) and the Triple Data Encryption Algorithm (TDES) specify
\r
36 * FIPS-approved cryptographic algorithms that can be used to protect electronic data. The TDES
\r
37 * bit in the TDES Mode Register (TDES_MR) is used to select either the single DES or the Triple
\r
38 * DES mode by function TDES_Configure().
\r
39 * A DES is capable of using cryptographic keys of 64 bits to encrypt and decrypt data in blocks of
\r
40 * 64 bits, Date input can be set with TDES_SetInput(). This 64-bit key is defined in the Key 1 Word
\r
41 * Registers (TDES_KEY1WRx) and set by TDES_WriteKey1. A TDES key consists of three DES keys,
\r
42 * which is also referred to as a key bundle. These three 64-bit keys are defined, respectively,
\r
43 * in the Key 1, 2 and 3 Word Registers (TDES_KEY1WRx, TDES_KEY2WRx and TDES_KEY3WRx).
\r
44 * In Triple DES mode (TDESMOD set to 1), the KEYMOD bit in the TDES Mode Register is used to choose between a two- and a three-key
\r
47 * To Enable a TDES encryption and decrypt,the user has to follow these few steps:
\r
49 * <li> A software triggered hardware reset of the TDES interface is performed by TDES_SoftReset().</li>
\r
50 * <li> Configure TDES algorithm mode, key mode, start mode and operation mode by TDES_Configure(). </li>
\r
51 * <li> Set DES key with fucntion TDES_WriteKey1(), TDES_WriteKey2(), or TDES_WriteKey3(). </li>
\r
52 * <li> To start the encryption or the decryption process with TDES_Start()</li>
\r
53 * <li> To get the encryption or decryption reslut by TDES_GetOutput() </li>
\r
56 * For more accurate information, please look at the TDES section of the
\r
68 * Implementation of Triple Data Encryption Standard (TDES).
\r
73 /*----------------------------------------------------------------------------
\r
75 *----------------------------------------------------------------------------*/
\r
79 /*----------------------------------------------------------------------------
\r
80 * Exported functions
\r
81 *----------------------------------------------------------------------------*/
\r
84 * \brief Starts Manual encryption/decryption process.
\r
86 void TDES_Start(void)
\r
88 TDES->TDES_CR = TDES_CR_START;
\r
92 * \brief Resets the TDES. A software triggered hardware reset of the TDES interface is performed.
\r
94 void TDES_SoftReset(void)
\r
96 TDES->TDES_CR = TDES_CR_SWRST;
\r
100 * \brief Restarts the countermeasures generator to an internal pre-defined value.
\r
102 void TDES_Recount(void)
\r
104 TDES->TDES_CR = TDES_CR_LOADSEED;
\r
108 * \brief Configures an TDES peripheral with the specified parameters.
\r
109 * \param mode Desired value for the TDES mode register (see the datasheet).
\r
111 void TDES_Configure(uint32_t mode)
\r
113 TDES->TDES_MR = mode;
\r
117 * \brief Enables the selected interrupts sources on a TDES peripheral.
\r
118 * \param sources Bitwise OR of selected interrupt sources.
\r
120 void TDES_EnableIt(uint32_t sources)
\r
122 TDES->TDES_IER = sources;
\r
126 * \brief Disables the selected interrupts sources on a TDES peripheral.
\r
127 * \param sources Bitwise OR of selected interrupt sources.
\r
129 void TDES_DisableIt(uint32_t sources)
\r
131 TDES->TDES_IDR = sources;
\r
135 * \brief Get the current status register of the given TDES peripheral.
\r
136 * \return TDES status register.
\r
138 uint32_t TDES_GetStatus(void)
\r
140 return TDES->TDES_ISR;
\r
145 * \param keyword0 key word 0
\r
146 * \param keyword0 key word 1
\r
148 void TDES_WriteKey1(uint32_t keyword0, uint32_t keyword1)
\r
150 TDES->TDES_KEY1WR[0] = keyword0;
\r
151 TDES->TDES_KEY1WR[1] = keyword1;
\r
156 * \param keyword0 key word 0
\r
157 * \param keyword0 key word 1
\r
159 void TDES_WriteKey2(uint32_t keyword0, uint32_t keyword1)
\r
161 TDES->TDES_KEY2WR[0] = keyword0;
\r
162 TDES->TDES_KEY2WR[1] = keyword1;
\r
167 * \param keyword0 key word 0
\r
168 * \param keyword0 key word 1
\r
170 void TDES_WriteKey3(uint32_t keyword0, uint32_t keyword1)
\r
172 TDES->TDES_KEY3WR[0] = keyword0;
\r
173 TDES->TDES_KEY3WR[1] = keyword1;
\r
177 * \brief Set the two 32-bit input Data allow to set the 64-bit data block used for encryption/decryption.
\r
178 * \param data0 corresponds to the first word of the data to be encrypted/decrypted
\r
179 * \param data1 corresponds to the last word of the data to be encrypted/decrypted
\r
181 void TDES_SetInput(uint32_t data0, uint32_t data1)
\r
183 TDES->TDES_IDATAR[0] = data0;
\r
184 TDES->TDES_IDATAR[1] = data1;
\r
188 * \brief Get the two 32-bit data contain the 64-bit data block which has been encrypted/decrypted.
\r
189 * \param data0 point to the first word.
\r
190 * \param data1 point to the last word.
\r
192 void TDES_GetOutput(uint32_t *data0, uint32_t *data1)
\r
194 *data0 = TDES->TDES_ODATAR[0];
\r
195 *data1 = TDES->TDES_ODATAR[1];
\r
199 * \brief Set the 64-bit initialization vector data block, which is used by some
\r
200 * modes of operation as an additional initial input.
\r
201 * \param v0 corresponds to the first word of the initialization vector.
\r
202 * \param v1 corresponds to the last word of the initialization vector.
\r
204 void TDES_SetVector(uint32_t v0, uint32_t v1)
\r
206 TDES->TDES_IVR[0] = v0;
\r
207 TDES->TDES_IVR[1] = v1;
\r
211 * \brief Set the 6-bit complete rounds.
\r
212 * \param rounds corresponds to rounds+1 complete round.
\r
214 void TDES_SetXteaRounds(uint32_t rounds)
\r
216 TDES->TDES_XTEA_RNDR = TDES_XTEA_RNDR_XTEA_RNDS(rounds);
\r