aboutsummaryrefslogblamecommitdiff
path: root/sw/test-sha256/test-sha256.c
blob: 9f7b3313030a7627b536c5a9fbfae29ec314c338 (plain) (tree)
1
2
3
4
5
6
7
8







                                                                        




                                                                                
                   




                                                                                
          
                                                                                
                              
                                                
 



                                                       



                                                                                


                                                                                
                                                                                
                 
 

                         
























































































                                                                                


                                                
                   







                              
                

           

 


                                                                        
//======================================================================
//
// test-sha256.c
// -------------
// test program for Cryptech Novena framwwork with EIM interface
// using the sha256 core.
//
//======================================================================

//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "novena-eim.h"


//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
#define SHA256_PREFIX (0x0000)
#define SHA_BASE (EIM_BASE_ADDR + SHA256_PREFIX)

#define DEMO_ADDER_BASE_ADDR (EIM_BASE_ADDR + 0x0000)
#define DEMO_ADDER_X_REG     (DEMO_ADDER_BASE_ADDR + 0)
#define DEMO_ADDER_Y_REG     (DEMO_ADDER_BASE_ADDR + 4)


//------------------------------------------------------------------------------
// Testing Parameters
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_regs() 
{
  unsigned int read_addr;
  unsigned int read_data;
  unsigned int write_addr;
  unsigned int write_data;
  unsigned int i;

//
//  for (i = 0 ; i < 0x40000 ; i += 4) {
//    read_addr = EIM_BASE_ADDR + i;
//    eim_read_32(read_addr, &read_data);
//    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
//  }

  read_addr = DEMO_ADDER_X_REG;
  eim_read_32(read_addr, &read_data);
  printf("address 0x%08x = 0x%08x\n", read_addr, read_data);

  read_addr = DEMO_ADDER_Y_REG;
  eim_read_32(read_addr, &read_data);
  printf("address 0x%08x = 0x%08x\n", read_addr, read_data);

  write_addr = DEMO_ADDER_Y_REG;
  write_data = 0xaa55aa55;
  eim_write_32(write_addr, &write_data);

  read_addr = DEMO_ADDER_Y_REG;
  eim_read_32(read_addr, &read_data);
  printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_sha256()
{
  unsigned int write_addr;
  unsigned int write_data;
  unsigned int read_addr;
  unsigned int read_data;
  int ok;
  unsigned int i;

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Try to iniate block processing and then dump 
  write_addr = SHA_BASE + 0x20;
  write_data = 0x00000001;
  eim_write_32(write_addr, &write_data);

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

  // Dump register contents. See if we have the core.
  for (i = 0 ; i < 200 ; i += 4) {
    read_addr = SHA_BASE + i;
    eim_read_32(read_addr, &read_data);
    printf("address 0x%08x = 0x%08x\n", read_addr, read_data);
  }

}

//------------------------------------------------------------------------------
// main()
//------------------------------------------------------------------------------
int main()
{
  int ok;
  unsigned int i;

  // try to setup eim (return value should be 1)
  printf("Configuring EIM .. ");
  ok = eim_setup();
  if (ok < 1) {
    printf("ERROR\n");
    return EXIT_FAILURE;
  }
  else {
    printf("EIM Setup ok.\n");
  }

  test_sha256();

  return 0;
}

//======================================================================
// EOF test-sha256.c
//======================================================================