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

Subversion Repositories avs_aes

[/] [avs_aes/] [trunk/] [sw/] [avs_aes.c] - Diff between revs 11 and 21

Show entire file | Details | Blame | View Log

Rev 11 Rev 21
Line 36... Line 36...
*/
*/
 
 
 
 
#include <avs_aes.h>
#include <avs_aes.h>
#include <string.h>
#include <string.h>
 
#include <stdint.h>
 
 
 
/** 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;
 
 
 
 
/**
 
 * \brief setup the context to be used later.
 
 * initializes the pointers to the correct memory locations
 
 * \param context : struct grouping address information
 
 */
 
void avs_aes_init(avs_aes_handle* context){
void avs_aes_init(avs_aes_handle* context){
        context->key    = (unsigned int*) KEY_ADDR;
        context->key    = (unsigned int*) KEY_ADDR;
        context->payload= (unsigned int*) DATA_ADDR;
        context->payload= (unsigned int*) DATA_ADDR;
        context->result = (unsigned int*) RESULT_ADDR;
        context->result = (unsigned int*) RESULT_ADDR;
        context->control        = (unsigned int*) AESCTRLWD;
        context->control        = (unsigned int*) AESCTRLWD;
        *(context->control) = 0x00000000;
        *(context->control) = 0x00000000;
}
}
 
 
 
 
/**
 
 * \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){
void avs_aes_setKey(avs_aes_handle* context, unsigned int* key){
        int i=0;
        int i=0;
        unsigned int* target_ptr = (unsigned int* )context->key;
        unsigned int* target_ptr = (unsigned int* )context->key;
        // Invalidate old key;
        /* Invalidate old key; */
        *(context->control) &= (~0x00000080);
        *(context->control) &= (~KEY_VALID);
 
        asm __volatile("sync" :::);
        for(i=0; i<KEYWORDS; i++){
        for(i=0; i<KEYWORDS; i++){
                *(target_ptr++) = *(key++);
                *(target_ptr++) = *(key++);
        }
        }
        // validate key;
        asm __volatile("sync" :::);
        *(context->control) |= 0x00000080;
        /* 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){
void avs_aes_setPayload(avs_aes_handle* context, unsigned int* payload){
        int i=0;
        int i=0;
        unsigned int* target_ptr = (unsigned int* )context->payload;
        unsigned int* target_ptr = (unsigned int* )context->payload;
        for(i=0; i<4; i++){
        for(i=0; i<4; i++){
                *(target_ptr++) = *(payload++);
                *(target_ptr++) = *(payload++);
        }
        }
}
}
 
 
 
 
 
 
/**
 
 * \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){
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){
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){
void avs_aes_decrypt(avs_aes_handle* context){
        *(context->control) |= 0x00000002;
        *(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);
        unsigned int mycontrol = *(context->control);
        return mycontrol & 0x03;
        return mycontrol & (DECRYPT | ENCRYPT);
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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