OpenCores
URL https://opencores.org/ocsvn/avs_aes/avs_aes/trunk

Subversion Repositories avs_aes

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /avs_aes/trunk/sw
    from Rev 11 to Rev 21
    Reverse comparison

Rev 11 → Rev 21

/AEStester.c
38,71 → 38,74
#include <string.h>
#include <avs_aes.h>
 
int main(){
avs_aes_handle context;
int i=0;
unsigned int result[4];
unsigned int Userkey[8] = {
0x11111111,0x22222222,0x33333333,0x44444444,
0x55555555,0x66666666,0x77777777,0x88888888};
unsigned int Payload[4] = {
0xAA555555,0xBB666666,0xCC777777,0xDD888888};
int main() {
avs_aes_handle context;
int i = 0;
 
unsigned int result[4];
unsigned int Userkey[] = {
0x11111111, 0x22222222,
0x33333333, 0x44444444,
0x55555555, 0x66666666,
0x77777777, 0x88888888
};
unsigned int Payload[] = {
0xAA555555, 0xBB666666,
0xCC777777, 0xDD888888
};
 
// START AES-Operations
printf("AES-Test\n");
avs_aes_init(&context);
avs_aes_setKey(&context,&Userkey);
avs_aes_setPayload(&context,&Payload);
avs_aes_encrypt(&context);
avs_aes_init(&context);
avs_aes_setKey(&context, &Userkey);
avs_aes_setPayload(&context, &Payload);
avs_aes_encrypt(&context);
 
while(avs_aes_isBusy(&context)){
printf("not ready\n");
}
printf("receiving 729cd44f 32a48d85 b8188185 c579ae49\n");
memcpy(result,context.result,4*sizeof(unsigned int));
for(i=0; i<4 ; i++){
printf("received 0x%X \n",result[i]);
}
while (avs_aes_isBusy(&context)) {
printf("not ready\n");
}
printf("receiving 729cd44f 32a48d85 b8188185 c579ae49\n");
memcpy(result, context.result, sizeof(result));
for (i = 0; i < 4; i++) {
printf("received 0x%X \n", result[i]);
}
 
// Decrypt same payload -
avs_aes_decrypt(&context);
while(avs_aes_isBusy(&context)){
printf("not ready\n");
}
printf("receiving 9c7076af ac2e5716 6681d3ac 014f64c0 \n");
memcpy(result,context.result,4*sizeof(unsigned int));
for(i=0; i<4 ; i++){
printf("received 0x%X \n",result[i]);
}
avs_aes_decrypt(&context);
while (avs_aes_isBusy(&context)) {
printf("not ready\n");
}
printf("receiving 9c7076af ac2e5716 6681d3ac 014f64c0 \n");
memcpy(result, context.result, sizeof(result));
for (i = 0; i < 4; i++) {
printf("received 0x%X \n", result[i]);
}
// Change payload ...
Payload[3] = 0x11111111;
Payload[2] = 0xAAAAAAAA;
Payload[1] = 0xCCCCCCCC;
Payload[2] = 0xAAAAAAAA;
Payload[1] = 0xCCCCCCCC;
Payload[0] = 0x00000000;
//new encryption
avs_aes_setPayload(&context,&Payload);
avs_aes_setPayload(&context, &Payload);
avs_aes_encrypt(&context);
while(avs_aes_isBusy(&context)){
printf("not ready\n");
}
memcpy(result,context.result,4*sizeof(unsigned int));
for(i=0; i<4 ; i++){
printf("received 0x%X \n",result[i]);
}
while (avs_aes_isBusy(&context)) {
printf("not ready\n");
}
memcpy(result, context.result, sizeof(result));
for (i = 0; i < 4; i++) {
printf("received 0x%X \n", result[i]);
}
//new decryption
avs_aes_decrypt(&context);
while(avs_aes_isBusy(&context)){
printf("not ready\n");
}
memcpy(result,context.result,4*sizeof(unsigned int));
for(i=0; i<4 ; i++){
printf("received 0x%X \n",result[i]);
}
printf("Done \n");
return 0;
avs_aes_decrypt(&context);
while (avs_aes_isBusy(&context)) {
printf("not ready\n");
}
memcpy(result, context.result, 4 * sizeof(unsigned int));
for (i = 0; i < 4; i++) {
printf("received 0x%X \n", result[i]);
}
printf("Done \n");
 
return 0;
 
}
/avs_aes.c
38,12 → 38,18
 
#include <avs_aes.h>
#include <string.h>
#include <stdint.h>
 
/**
* \brief setup the context to be used later.
* initializes the pointers to the correct memory locations
* \param context : struct grouping address information
*/
/** memory offset for key DON'T CHANGE! */
const uint32_t KEY_ADDR = AES_BASEADDR;
/** memory offset of payload */
const uint32_t DATA_ADDR = AES_BASEADDR+0x08;
/** memory offset of result */
const uint32_t RESULT_ADDR = AES_BASEADDR+0x10;
/** memory offset for control word */
const uint32_t AESCTRLWD = AES_BASEADDR+0x18;
 
 
void avs_aes_init(avs_aes_handle* context){
context->key = (unsigned int*) KEY_ADDR;
context->payload= (unsigned int*) DATA_ADDR;
53,31 → 59,21
}
 
 
/**
* \brief setup the context to be used later.
* initializes the pointers to the correct memory locations
* \param context struct grouping address information
* \param key user key to load
*/
void avs_aes_setKey(avs_aes_handle* context, unsigned int* key){
int i=0;
unsigned int* target_ptr = (unsigned int* )context->key;
// Invalidate old key;
*(context->control) &= (~0x00000080);
/* Invalidate old key; */
*(context->control) &= (~KEY_VALID);
asm __volatile("sync" :::);
for(i=0; i<KEYWORDS; i++){
*(target_ptr++) = *(key++);
}
// validate key;
*(context->control) |= 0x00000080;
asm __volatile("sync" :::);
/* validate key */
*(context->control) |= KEY_VALID;
}
 
 
/**
* \brief loads payload for processing to the core
* basically memcopy...
* \param context struct grouping address information
* \param payload user data to be processed
*/
void avs_aes_setPayload(avs_aes_handle* context, unsigned int* payload){
int i=0;
unsigned int* target_ptr = (unsigned int* )context->payload;
87,42 → 83,25
}
 
 
 
/**
* \brief set the KEY_VALID flag in the control word
* used to signal the completion of writing the key ( \ref avs_aes_setKey )
* \param context struct grouping address information
*/
void avs_aes_setKeyvalid(avs_aes_handle* context){
*(context->control) |= 0x00000080;
*(context->control) |= KEY_VALID;
asm __volatile("sync" :::);
}
 
 
/**
* \brief set the ENCRYPT flag in the control word
* start encryption of (hopefully) previously loaded payload
* \param context struct grouping address information
*/
void avs_aes_encrypt(avs_aes_handle* context){
*(context->control) |= 0x00000001;
*(context->control) |= ENCRYPT;
asm __volatile("sync" :::);
}
 
/**
* \brief set the DECRYPT flag in the control word
* start encryption of (hopefully) previously loaded payload
* \param context struct grouping address information
*/
void avs_aes_decrypt(avs_aes_handle* context){
*(context->control) |= 0x00000002;
 
void avs_aes_decrypt(avs_aes_handle* context) {
*(context->control) |= DECRYPT;
asm __volatile("sync" :::);
}
 
/**
* \brief checks the COMPLETED flag
* can be used for ugly polling the slave if IRQs are not used
* \param context struct grouping address information
* \return 1 if still computing 0 if done.
*/
int avs_aes_isBusy(avs_aes_handle* context){
 
int avs_aes_isBusy(avs_aes_handle* context) {
unsigned int mycontrol = *(context->control);
return mycontrol & 0x03;
return mycontrol & (DECRYPT | ENCRYPT);
}
/avs_aes.h
1,43 → 1,42
/**
* \file avs_aes.h
* \brief header file for AES Avalon IP Core software driver
* offers interfaces to convinient access to the core
*
* This file is part of the project avs_aes
* see: http://opencores.org/project,avs_aes
*
*
* \section AUTHORS
* Thomas Ruschival -- ruschi@opencores.org (www.ruschival.de)
*
* \section LICENSE
* Copyright (c) 2009, Authors and opencores.org
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the organization nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE
*/
* \file avs_aes.h
* \brief header file for AES Avalon IP Core software driver
* offers interfaces to convinient access to the core
*
* This file is part of the project avs_aes
* see: http://opencores.org/project,avs_aes
*
*
* \section AUTHORS
* Thomas Ruschival -- ruschi@opencores.org (www.ruschival.de)
*
* \section LICENSE
* Copyright (c) 2009, Authors and opencores.org
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the organization nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE
*/
 
 
#ifndef AVS_AES_H_
#define AVS_AES_H_
 
49,53 → 48,58
#ifndef KEYWORDS
/**
* Keylength 256 Bit AES
*/
*/
#define KEYWORDS 8
#endif /* KEYWORDS */
 
#ifndef AES_BASEADDR
/**
/**
* base address of the Avalon Slave component in memory map
*/
*/
#define AES_BASEADDR 0x40000
#endif /* AES_BASEADDR */
 
 
/**
* \section Constants
* Constants no need to change them!
* \addtogroup control-register
* Bits in Control Register
* \see{avs_aes_handle::control}
* \{
*/
/** memory offset for key DON'T CHANGE! */
#define KEY_ADDR AES_BASEADDR+0x00
/** memory offset of payload DON'T CHANGE!*/
#define DATA_ADDR AES_BASEADDR+0x08
/** memory offset of result DON'T CHANGE! */
#define RESULT_ADDR AES_BASEADDR+0x10
/** memory offset for control word DON'T CHANGE! */
#define AESCTRLWD AES_BASEADDR+0x18
 
/** Signal load of new key valid \see{avs_aes_handle::control} */
#define KEY_VALID (1 << 7)
/** Enable interrupt bit \see{avs_aes_handle::control} */
#define IRQ_ENA (1 << 6)
/** Start decryption bit \see{avs_aes_handle::control} */
#define DECRYPT (1 << 1)
/** start encryption bit \see{avs_aes_handle::control} */
#define ENCRYPT (1 << 0)
 
/** \} */
 
/**
* \brief object storing addresses for this Avalon AES slave
* might be useful in case there are more attached, also for convinience
*/
typedef struct{
/**
* \brief pointer "KEY" field in memory mapping
*/
typedef struct {
/**
* \brief pointer to key field in memory mapping
*/
volatile unsigned int* key;
/**
* \brief pointer "data" field in memory mapping
* used for both decryption and encryption
/**
* \brief pointer to data field in memory mapping
* used for both decryption and encryption
*/
volatile unsigned int* payload;
/**
* \brief pointer "RESULT" field in memory mapping
/**
* \brief pointer to result field in memory mapping
*/
volatile unsigned int* result;
/**
* \brief pointer to control word
*/
volatile unsigned int* control;
/**
* \brief pointer to control word
*/
volatile unsigned int* control;
 
} avs_aes_handle;
 
/**
102,7 → 106,6
* \section functions
**/
 
 
/**
* \brief setup the context to be used later.
* initializes the pointers to the correct memory locations
111,8 → 114,8
void avs_aes_init(avs_aes_handle* context);
 
/**
* \brief setup the context to be used later.
* initializes the pointers to the correct memory locations
* \brief Set a new key
* This call asserts the KEY_VALID flag and triggers the key-expansion in the core
* \param context struct grouping address information
* \param key user key to load
*/
145,7 → 148,7
* start encryption of (hopefully) previously loaded payload
* \param context struct grouping address information
*/
void avs_aes_decrypt( avs_aes_handle* context);
void avs_aes_decrypt(avs_aes_handle* context);
 
/**
* \brief checks the COMPLETED flag
155,5 → 158,4
*/
int avs_aes_isBusy(avs_aes_handle* context);
 
 
#endif /*AVS_AES_H_*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.