aboutsummaryrefslogblamecommitdiff
path: root/sw/modexp_tester.c
blob: 2288ad5cab84b043f29e2821a898987c9f9ddd07 (plain) (tree)














































                                                                           









                                                                    





                                         



























































                                                                      
 




                                             
                                                   






                                             
                                                        
















                                                                    
 




                                              
                                                   

























                                                                    
 




                                             
                                                   
















                                                                    
               
  
                          
                                                                    
                        
 



                                              
 




                                             
 
                                              
                                              
                                              

 





                                                                    
























                                                                     
 







                                                                    




























                                                                    
                                            


                                        
                                                                          








                                                                    









                                                                    



                                     
                 


                                                        

                                                                  
             

                        
                            













                                                                    



                                     
                 


                                                         


                                                                  
             

                        
                            













                                                                    



                                     
                 


                                                        

                                                                  
             

                        
                            






                                                                    





                                         


                                                                    



                                                 
                 
 
                                                                                                                 
 

                                                                  
             

                        
                            



                                                                    





                                                                    



                                                                         
                 
 
                                            
 

                                                                  
             

                        
                            



                                                                    

























































                                                                                    

        
                                   











































































                                                                        
                                                









                                                                    























































                                                                                    
 





































                                                                                    


                 
                                                                           
 
                                                                    

             
                                            
      
                                                



                                                                    
         
                                                                    
              

                        
                      




                         









                 




                                                                        
                      
                                                                        
//======================================================================
//
// modexp_tester.c
// ---------------
// Simple test sw for the modexp.
//
//
// Author: Joachim Strombergson, Rob Austein,
// Copyright (c) 2014-2015, NORDUnet A/S 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 NORDUnet 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.
//
//
//======================================================================

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "cryptech.h"

//------------------------------------------------------------------
// Global defines.
//------------------------------------------------------------------
#define VERBOSE 0
#define CHECK_WRITE 0


//------------------------------------------------------------------
// Robs macros. Scary scary.
//------------------------------------------------------------------
#define check(_expr_)			\
  do {					\
    if ((_expr_) != 0) {		\
      printf("%s failed\n", #_expr_);	\
      exit(1);				\
    }					\
  } while (0)


//------------------------------------------------------------------
// tc_w32()
//
// Write 32-bit word to given address.
//------------------------------------------------------------------
static void tc_w32(const off_t addr, const uint32_t data)
{
  uint8_t w[4];
  w[0] = data >> 24 & 0xff;
  w[1] = data >> 16 & 0xff;
  w[2] = data >> 8  & 0xff;
  w[3] = data       & 0xff;
  check(tc_write(addr, w, 4));
}


//------------------------------------------------------------------
// tc_r32
//
// Read 32-bit word from given address.
//------------------------------------------------------------------
static uint32_t tc_r32(const off_t addr)
{
  uint8_t w[4];
  check(tc_read(addr, w, 4));
  return (uint32_t)((w[0] << 24) + (w[1] << 16) + (w[2] << 8) + w[3]);
}


//------------------------------------------------------------------
// check_modexp_access
//
// Check that we can read from the modexp core by trying to
// read out the name and version.
//------------------------------------------------------------------
static void check_modexp_access(void)
{
  uint8_t name0[4], name1[4], version[4];

  printf("Trying to read the modexp core name\n");

  check(tc_read(MODEXP_ADDR_NAME0,   name0,    sizeof(name0)));
  check(tc_read(MODEXP_ADDR_NAME1,   name1,    sizeof(name1)));
  check(tc_read(MODEXP_ADDR_VERSION, version, sizeof(version)));
  printf("%4.4s%4.4s %4.4s\n\n", name0, name1, version);
}


//------------------------------------------------------------------
// check_modulus_mem()
//
// Check that we can write and read to the modulus memory.
//------------------------------------------------------------------
static void check_modulus_mem(void)
{
  uint8_t i;
  uint32_t j;

  printf("Testing modulus mem access.\n");

  tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
  // Write test data to modulus mempory.
  for (i = 0 ; i < 64; i = i + 1) {
    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) +
      ((i * 4 + 1) << 8) + i * 4;
    tc_w32(MODEXP_MODULUS_DATA, j);
  }

  tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
  // Read out test data from modulus mempory.
  for (i = 0 ; i < 64 ; i = i + 4) {
    printf("modulus mem: 0x%08x 0x%08x 0x%08x 0x%08x\n",
	   tc_r32(MODEXP_MODULUS_DATA),
	   tc_r32(MODEXP_MODULUS_DATA),
	   tc_r32(MODEXP_MODULUS_DATA),
	   tc_r32(MODEXP_MODULUS_DATA));
  }
}


//------------------------------------------------------------------
// check_exponent_mem()
//
// Check that we can write and read to the exponent memory.
//------------------------------------------------------------------
static void check_exponent_mem(void)
{
  uint8_t i;
  uint32_t j;

  printf("Testing exponent mem access.\n");

  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  // Write test data to exponent memory.
  for (i = 0 ; i < 64; i = i + 1) {
    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) +
      ((i * 4 + 1) << 8) + i * 4;
    tc_w32(MODEXP_EXPONENT_DATA, j);
  }

  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  // Read out test data from exponent memory.
  for (i = 0 ; i < 64 ; i = i + 4) {
    printf("exponent mem: 0x%08x 0x%08x 0x%08x 0x%08x\n",
	   tc_r32(MODEXP_EXPONENT_DATA),
	   tc_r32(MODEXP_EXPONENT_DATA),
	   tc_r32(MODEXP_EXPONENT_DATA),
	   tc_r32(MODEXP_EXPONENT_DATA));
  }
}



//------------------------------------------------------------------
// check_message_mem()
//
// Check that we can write and read to the message memory.
//------------------------------------------------------------------
static void check_message_mem(void)
{
  uint8_t i;
  uint32_t j;

  printf("Testing message mem access.\n");

  tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
  // Write test data to message memory.
  for (i = 0 ; i < 64; i = i + 1) {
    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) +
      ((i * 4 + 1) << 8) + i * 4;
    tc_w32(MODEXP_MESSAGE_DATA, j);
  }

  tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
  // Read out test data from messsage memory.
  for (i = 0 ; i < 64 ; i = i + 4) {
    printf("message mem: 0x%08x 0x%08x 0x%08x 0x%08x\n",
	   tc_r32(MODEXP_MESSAGE_DATA),
	   tc_r32(MODEXP_MESSAGE_DATA),
	   tc_r32(MODEXP_MESSAGE_DATA),
	   tc_r32(MODEXP_MESSAGE_DATA));
  }
}


//------------------------------------------------------------------
// clear_mems()
//
// Zero fill the memories.
//------------------------------------------------------------------
static void clear_mems()
{
  uint32_t i;
  tc_w32(MODEXP_MESSAGE_PTR_RST,  0x00000000);
  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  tc_w32(MODEXP_MODULUS_PTR_RST,  0x00000000);

  for (i = 0 ; i < 256 ; i++) {
    tc_w32(MODEXP_MESSAGE_DATA,  0x00000000);
    tc_w32(MODEXP_EXPONENT_DATA, 0x00000000);
    tc_w32(MODEXP_MODULUS_DATA,  0x00000000);
  }

  tc_w32(MODEXP_MESSAGE_PTR_RST,  0x00000000);
  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  tc_w32(MODEXP_MODULUS_PTR_RST,  0x00000000);
}


//------------------------------------------------------------------
// dump_mems()
//
// Dump the first words from the memories.
//------------------------------------------------------------------
static void dump_mems()
{
  tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
  printf("First words in messagee mem:\n");
  printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
	 tc_r32(MODEXP_MESSAGE_DATA), tc_r32(MODEXP_MESSAGE_DATA),
	 tc_r32(MODEXP_MESSAGE_DATA), tc_r32(MODEXP_MESSAGE_DATA));

  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  printf("First words in exponent mem:\n");
  printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
	 tc_r32(MODEXP_EXPONENT_DATA), tc_r32(MODEXP_EXPONENT_DATA),
	 tc_r32(MODEXP_EXPONENT_DATA), tc_r32(MODEXP_EXPONENT_DATA));

  tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
  printf("First words in modulus mem:\n");
  printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
	 tc_r32(MODEXP_MODULUS_DATA), tc_r32(MODEXP_MODULUS_DATA),
	 tc_r32(MODEXP_MODULUS_DATA), tc_r32(MODEXP_MODULUS_DATA));

  tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
  printf("First words in result mem:\n");
  printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
	 tc_r32(MODEXP_RESULT_DATA), tc_r32(MODEXP_RESULT_DATA),
	 tc_r32(MODEXP_RESULT_DATA), tc_r32(MODEXP_RESULT_DATA));

  tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
  tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
}


//------------------------------------------------------------------
// testrunner()
//------------------------------------------------------------------
uint8_t testrunner(uint32_t exp_len, uint32_t *exponent,
                   uint32_t mod_len, uint32_t *modulus,
                   uint32_t *message, uint32_t *expected)
{
  uint32_t i;
  uint32_t result;
  uint8_t correct;

  tc_w32(MODEXP_EXPONENT_LENGTH, exp_len);
  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
  for (i = 0 ; i < mod_len ; i++) {
    tc_w32(MODEXP_EXPONENT_DATA, exponent[i]);
  }

  tc_w32(MODEXP_MODULUS_LENGTH, mod_len);
  tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
  tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
  for (i = 0 ; i < mod_len ; i++) {
    tc_w32(MODEXP_MESSAGE_DATA, message[i]);
    tc_w32(MODEXP_MODULUS_DATA, modulus[i]);
  }

  tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
  check(tc_wait_ready(MODEXP_ADDR_STATUS));

  correct = 1;

  tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
  for (i = 0 ; i < mod_len ; i++) {
    result = tc_r32(MODEXP_RESULT_DATA);
    if (result != expected[i]) {
      printf("Error. Expected 0x%08x, got 0x%08x\n", expected[i], result);
      correct = 0;
    }
  }

  return correct;
}


//------------------------------------------------------------------
// tc1()
//
// c = m ** e % N with the following (decimal) test values:
//  m = 3
//  e = 7
//  n = 11 (0x0b)
//  c = 3 ** 7 % 11 = 9
//------------------------------------------------------------------
static void tc1()
{
  uint32_t exponent[] = {0x00000007};
  uint32_t modulus[]  = {0x0000000b};
  uint32_t message[]  = {0x00000003};
  uint32_t expected[] = {0x00000009};
  uint8_t result;

  printf("Running TC1: 0x03 ** 0x07 mod 0x0b = 0x09\n");

  result = testrunner(1, exponent, 1, modulus, message, expected);

  if (result)
    printf("TC1: OK\n");
  else
    printf("TC1: NOT OK\n");
}


//------------------------------------------------------------------
// tc2()
//
// c = m ** e % N with the following test values:
//  m = 251 (0xfb)
//  e = 251 (0xfb)
//  n = 257 (0x101)
//  c = 251 ** 251 % 257 = 183 (0xb7)
//------------------------------------------------------------------
static void tc2()
{
  uint32_t exponent[] = {0x000000fb};
  uint32_t modulus[]  = {0x00000101};
  uint32_t message[]  = {0x000000fb};
  uint32_t expected[] = {0x000000b7};
  uint8_t result;

  printf("Running TC2: 0xfb ** 0xfb mod 0x101 = 0xb7\n");


  result = testrunner(1, exponent, 1, modulus, message, expected);

  if (result)
    printf("TC2: OK\n");
  else
    printf("TC2: NOT OK\n");
}


//------------------------------------------------------------------
// tc3()
//
// c = m ** e % N with the following test values:
//  m = 0x81
//  e = 0x41
//  n = 0x87
//  c = 0x81 ** 0x41 % 0x87 = 0x36
//------------------------------------------------------------------
static void tc3()
{
  uint32_t exponent[] = {0x00000041};
  uint32_t modulus[]  = {0x00000087};
  uint32_t message[]  = {0x00000081};
  uint32_t expected[] = {0x00000036};
  uint8_t result;

  printf("Running TC3: 0x81 ** 0x41 mod 0x87 = 0x36\n");

  result = testrunner(1, exponent, 1, modulus, message, expected);

  if (result)
    printf("TC3: OK\n");
  else
    printf("TC3: NOT OK\n");
}


//------------------------------------------------------------------
// tc4()
//
// c = m ** e % N with the following test values:
//  m = 0x00000001946473e1
//  e = 0xh000000010e85e74f
//  n = 0x0000000170754797
//  c = 0x000000007761ed4f
//
// These operands spans two 32-bit words.
//------------------------------------------------------------------
static void tc4()
{
  uint32_t exponent[] = {0x00000001, 0x0e85e74f};
  uint32_t modulus[]  = {0x00000001, 0x70754797};
  uint32_t message[]  = {0x00000001, 0x946473e1};
  uint32_t expected[] = {0x00000000, 0x7761ed4f};
  uint8_t result;

  printf("Running TC4: 0x00000001946473e1 ** 0xh000000010e85e74f mod 0x0000000170754797 = 0x000000007761ed4f\n");

  result = testrunner(2, exponent, 2, modulus, message, expected);

  if (result)
    printf("TC4: OK\n");
  else
    printf("TC4: NOT OK\n");
}


//------------------------------------------------------------------
// tc5()
//
// c = m ** e % N with 128 bit operands.
//------------------------------------------------------------------
static void tc5()
{
  uint32_t exponent[] = {0x3285c343, 0x2acbcb0f, 0x4d023228, 0x2ecc73db};
  uint32_t modulus[]  = {0x267d2f2e, 0x51c216a7, 0xda752ead, 0x48d22d89};
  uint32_t message[]  = {0x29462882, 0x12caa2d5, 0xb80e1c66, 0x1006807f};
  uint32_t expected[] = {0x0ddc404d, 0x91600596, 0x7425a8d8, 0xa066ca56};
  uint8_t result;

  printf("Running TC5: 128 bit operands\n");

  result = testrunner(4, exponent, 4, modulus, message, expected);

  if (result)
    printf("TC5: OK\n");
  else
    printf("TC5: NOT OK\n");
}


//------------------------------------------------------------------
// tc6()
//
// e = 65537 and message, modulus are 64 bit oprerands.
//------------------------------------------------------------------
static void tc6()
{
  uint32_t message[] = {0x00000000, 0xdb5a7e09, 0x86b98bfb};

  uint32_t exponent[] = {0x00000000, 0x00000000, 0x00010001};

  uint32_t modulus[] = {0x00000000, 0xb3164743, 0xe1de267d};

  uint32_t expected[] = {0x00000000, 0x9fc7f328, 0x3ba0ae18};
  uint8_t result;

  printf("Running TC6: e=65537 and 64 bit operands\n");

  result = testrunner(3, exponent, 3, modulus, message, expected);

  if (result)
    printf("TC6: OK\n");
  else
    printf("TC6: NOT OK\n");
}


//------------------------------------------------------------------
// tc7()
//
// e = 65537 and message, modulus are 256 bit oprerands.
//------------------------------------------------------------------
static void tc7()
{
  uint32_t message[] = {0x00000000, 0xbd589a51, 0x2ba97013, 0xc4736649, 0xe233fd5c,
			0x39fcc5e5, 0x2d60b324, 0x1112f2d0, 0x1177c62b};

  uint32_t exponent[] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
			 0x00000000, 0x00000000, 0x00000000, 0x00010001};

  uint32_t modulus[] = {0x00000000, 0xf169d36e, 0xbe2ce61d, 0xc2e87809, 0x4fed15c3,
			0x7c70eac5, 0xa123e643, 0x299b36d2, 0x788e583b};

  uint32_t expected[] = {0x00000000, 0x7c5f0fee, 0x73028fc5, 0xc4fe57c4, 0x91a6f5be,
			 0x33a5c174, 0x2d2c2bcd, 0xda80e7d6, 0xfb4c889f};
  uint8_t result;

  printf("Running TC7: e=65537 and 256 bit operands\n");

  result = testrunner(9, exponent, 9, modulus, message, expected);

  if (result)
    printf("TC7: OK\n");
  else
    printf("TC7: NOT OK\n");
}


//------------------------------------------------------------------
// tc8()
//
// Testcase with 1024 bit operands.
//------------------------------------------------------------------
static void tc8()
{
  uint32_t message[] = {0x00000000, 0xc1dded3d, 0x28434587, 0xcccdffa8,
                        0xc98a9a1c, 0x04a6eb9f, 0xcf672252, 0x3ca88273,
                        0x4fa3868a, 0xd2228ce5, 0x005f7876, 0x2abbc04b,
                        0x04d86c72, 0x8466923d, 0x41d7077b, 0x950250b9,
                        0xb0044ecd, 0x440bd649, 0x23a57ce7, 0xd5651065,
                        0xa7aab420, 0x4a6f7a81, 0x433c6761, 0xe5a44ca7,
                        0x903dfee9, 0xcf7946a7, 0x22914c75, 0xbd0204ab,
                        0x192f78ad, 0xd45811cd, 0xa1b58078, 0x3ed0a735,
                        0xd81e6402, 0x2faf947c, 0xe7b85734, 0x18ada37a,
                        0xd438e4ce, 0xb9e2a374, 0x88968bf2, 0xe2db443c,
                        0xa9e8bb02, 0x32bca770, 0xa2964ec0, 0x782d3bd5,
                        0x575dc836, 0xd57f2b1b, 0x444300b2, 0x07889868,
                        0xb6f174dc, 0x0663243e, 0x93c14967, 0x4696ffb1,
                        0xd7c9a423, 0x1168031b, 0x55577481, 0x91ed0cde,
                        0x5ba3fc60, 0x55845380, 0x21dc1d33, 0x2c5fa2e5,
                        0xbc12c97e, 0x4bcc04ea, 0x692a309d, 0x8e1c9e02,
                        0xaa1c0a3d };

  uint32_t exponent[] = {0x00000000, 0x19f18035, 0xcc60d544, 0x19d27c61,
                         0x8ed90eb3, 0x3690e87d, 0x773ca91e, 0xdade42b8,
                         0x0a3f677f, 0x7f0bf0c3, 0xad92b9fb, 0x52db2b4c,
                         0x8aa72367, 0x0a449805, 0x1b3b511c, 0x1d7e7d6b,
                         0x741a1b6a, 0x3d8800fe, 0x547dfdc2, 0xa802c31a,
                         0xfefb2a15, 0xce0ab737, 0x1fa90820, 0xdf80b4ea,
                         0x9ce78816, 0xb782861e, 0x7af81e25, 0x4343e5bf,
                         0xebe0b724, 0x6ece76ab, 0x01aa5089, 0xe4e21ba3,
                         0x248b6b0d, 0x1c091b64, 0x9c37f319, 0x22c25e57,
                         0x5a7448d1, 0x5a8300da, 0x1278cd36, 0x0cb4c6ac,
                         0x8deed224, 0xb7fdd7d0, 0x6326c04d, 0x539fff6f,
                         0x63778630, 0x85468bf5, 0x5a9c33f7, 0x160efc5c,
                         0xf8e4b6d1, 0x353bd641, 0x117508cc, 0xd1996bc5,
                         0x0a392c11, 0xb0e1ffe8, 0xe7b14a2e, 0x5013a5af,
                         0xbcce99d5, 0x8b93bd75, 0xa4e198d7, 0x4c18c142,
                         0xe51872d5, 0x7ef0cf34, 0x3ae53a47, 0xf5297694,
                         0xfd0c2275 };

  uint32_t modulus[] = {0x00000000, 0xd49c6a62, 0xae09979b, 0x5337cdad,
                        0xb457e3f7, 0x5550dd37, 0x05180d6d, 0xf5fbe3a5,
                        0xa108dbf3, 0x88629746, 0xca129de2, 0x8302471f,
                        0x15058a33, 0x97c1d786, 0xf87da044, 0x13acbbe8,
                        0x9dad545c, 0xdd778482, 0x24f3bf5b, 0x42473afd,
                        0x89b05301, 0x9299817b, 0xc1222669, 0x4ec4a193,
                        0x274889fa, 0xcd1bce7a, 0x41b5310d, 0xf86b14a4,
                        0x5673ea86, 0x521b8374, 0xd28da0ac, 0xc84464f1,
                        0x1ec80fe6, 0xe75ecc90, 0x6c34aee2, 0xa627e90f,
                        0xb7688407, 0x41833bdf, 0x411ab5da, 0x6759d67b,
                        0x182bc41a, 0x910dfa56, 0xf6e345de, 0xe1aae4d1,
                        0xa7c63ba1, 0xd65aa619, 0xd8b2c716, 0x483cdc54,
                        0x516ba960, 0xa221a1c4, 0xee39e3c3, 0x0d839205,
                        0xd6adba6a, 0xc8fa9741, 0x4434bab7, 0x0cb18c9c,
                        0x75c967d4, 0xb15febac, 0x7237454e, 0x72087e79,
                        0xd9e1acf1, 0xfc374a56, 0xa7741ed9, 0xc16ad5d8,
                        0x285d4f41 };

  uint32_t expected[] = {0x00000000, 0x0a311e48, 0x0d000a72, 0x1abe90c3,
                         0xfde69c22, 0xb68a5512, 0x9e0e3179, 0x9830556f,
                         0xb3012eaf, 0xc2e02fc5, 0x5dded2d0, 0xc5c7ad29,
                         0x9292ab12, 0x60393a6a, 0x81f2ce8a, 0xdffaf8e3,
                         0xc719e252, 0x5961a5fc, 0x6b29d3e5, 0x3421e018,
                         0xec174916, 0xa1ae3027, 0xf9bdec45, 0xe67ab6fa,
                         0x7ae109d1, 0xb840fc18, 0x1a8a17cc, 0xee81b969,
                         0x7bb5db8e, 0x5263943a, 0xa55ee6cd, 0x62c716f5,
                         0x830bfe99, 0x39f77d9d, 0x6684b8e4, 0xfae01bbd,
                         0xe04cb546, 0x7205a682, 0x7aba9d46, 0xd02a3970,
                         0x106d3dc0, 0x9ee094b5, 0xdc454b0b, 0x6661c887,
                         0x731569cb, 0xa37867cd, 0x3fe6992a, 0xed571459,
                         0x41585bf3, 0x8bc4979f, 0x1dc42dc1, 0xc44e2f03,
                         0xbd1e3599, 0xab66c76d, 0x0fac6628, 0x3eaef9fe,
                         0xaac66e77, 0x07ef4d15, 0x5f2bc8f1, 0xa8299364,
                         0xfea22998, 0xf55f7ee7, 0xdb61eef0, 0x898e8c64,
                         0xd5535329 };
  uint8_t result;

  printf("Running TC8: 1024 bit operands...\n");

  result = testrunner(65, exponent, 65, modulus, message, expected);

  if (result)
    printf("TC8: OK\n");
  else
    printf("TC8: NOT OK\n");
}


void rob_dec_1024(void)
{
  uint32_t exponent[] = {0x00000000, 0x3ff26c9e, 0x32685b93, 0x66570228, 0xf0603c4e,
                         0x04a717c1, 0x8038b116, 0xeb48325e, 0xcada992a,
                         0x920bb241, 0x5aee4afe, 0xe2a37e87, 0xb35b9519,
                         0xb335775d, 0x989553e9, 0x1326f46e, 0x2cdf6b7b,
                         0x84aabfa9, 0xef24c600, 0xb56872ad, 0x5edb9041,
                         0xe8ecd7f8, 0x535133fb, 0xdefc92c7, 0x42384226,
                         0x7d40e5f5, 0xc91bd745, 0x9578e460, 0xfc858374,
                         0x3172bed3, 0x73b6957c, 0xc0d6a68e, 0x33156a61};


  uint32_t modulus[] = {0x00000000, 0xd075ec0a, 0x95048ef8, 0xcaa69073, 0x8d9d58e9,
                        0x1764b437, 0x50b58cad, 0x8a6e3199, 0x135f80ee,
                        0x84eb2bde, 0x58d38ee3, 0x5825e91e, 0xafdeb1ba,
                        0xa15a160b, 0x0057c47c, 0xc7765e31, 0x868a3e15,
                        0x5ee57cef, 0xb008c4dd, 0x6a0a89ee, 0x98a4ee9c,
                        0x971a07de, 0x61e5b0d3, 0xcf70e1cd, 0xc6a0de5b,
                        0x451f2fb9, 0xdb995196, 0x9f2f884b, 0x4b09749a,
                        0xe6c4ddbe, 0x7ee61f79, 0x265c6adf, 0xb16b3015};


  uint32_t message[] = {0x00000000, 0x0001ffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0x00303130,
                        0x0d060960, 0x86480165, 0x03040201, 0x05000420,
                        0x8e36fc9a, 0xa31724c3, 0x2416263c, 0x0366a175,
                        0xfabbb92b, 0x741ca649, 0x6107074d, 0x0343b597};


  uint32_t expected[] = {0x00000000, 0x06339a64, 0x367db02a, 0xf41158cc, 0x95e76049,
                         0x4519c165, 0x111184be, 0xe41d8ee2, 0x2ae5f5d1,
                         0x1da7f962, 0xac93ac88, 0x915eee13, 0xa3350c22,
                         0xf0dfa62e, 0xfdfc2b62, 0x29f26e27, 0xbebdc84e,
                         0x4746df79, 0x7b387ad2, 0x13423c9f, 0x98e8a146,
                         0xff486b6c, 0x1a85414e, 0x73117121, 0xb700e547,
                         0xab4e07b2, 0x21b988b8, 0x24dd77c2, 0x046b0a20,
                         0xcddb986a, 0xac75c2f2, 0xb044ed59, 0xea565879};

  uint8_t result;

  printf("=== Running 1024 bit decipher/sign test from Robs RSA code. ===\n");

  result = testrunner(33, exponent, 33, modulus, message, expected);

  if (result)
    printf("Rob 1024 dec/sign test OK\n");
  else
    printf("Rob 1024 dec/sign test NOT OK\n");

}


void rob_enc_1024(void)
{
  uint32_t exponent[] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00000000,
                         0x00000000, 0x00000000, 0x00000000, 0x00010001};


  uint32_t modulus[] = {0x00000000, 0xd075ec0a, 0x95048ef8, 0xcaa69073, 0x8d9d58e9,
                        0x1764b437, 0x50b58cad, 0x8a6e3199, 0x135f80ee,
                        0x84eb2bde, 0x58d38ee3, 0x5825e91e, 0xafdeb1ba,
                        0xa15a160b, 0x0057c47c, 0xc7765e31, 0x868a3e15,
                        0x5ee57cef, 0xb008c4dd, 0x6a0a89ee, 0x98a4ee9c,
                        0x971a07de, 0x61e5b0d3, 0xcf70e1cd, 0xc6a0de5b,
                        0x451f2fb9, 0xdb995196, 0x9f2f884b, 0x4b09749a,
                        0xe6c4ddbe, 0x7ee61f79, 0x265c6adf, 0xb16b3015};


  uint32_t message[] = {0x00000000, 0x0001ffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
                        0xffffffff, 0xffffffff, 0xffffffff, 0x00303130,
                        0x0d060960, 0x86480165, 0x03040201, 0x05000420,
                        0x8e36fc9a, 0xa31724c3, 0x2416263c, 0x0366a175,
                        0xfabbb92b, 0x741ca649, 0x6107074d, 0x0343b597};


  uint32_t expected[] = {0x00000000, 0x06339a64, 0x367db02a, 0xf41158cc, 0x95e76049,
                         0x4519c165, 0x111184be, 0xe41d8ee2, 0x2ae5f5d1,
                         0x1da7f962, 0xac93ac88, 0x915eee13, 0xa3350c22,
                         0xf0dfa62e, 0xfdfc2b62, 0x29f26e27, 0xbebdc84e,
                         0x4746df79, 0x7b387ad2, 0x13423c9f, 0x98e8a146,
                         0xff486b6c, 0x1a85414e, 0x73117121, 0xb700e547,
                         0xab4e07b2, 0x21b988b8, 0x24dd77c2, 0x046b0a20,
                         0xcddb986a, 0xac75c2f2, 0xb044ed59, 0xea565879};

  uint8_t result;

  printf("=== Running 1024 bit enc/verify test from Robs RSA code. ===\n");

  result = testrunner(33, exponent, 33, modulus, expected, message);

  if (result)
    printf("Rob 1024 enc/verify test OK\n");
  else
    printf("Rob 1024 enc/verify test NOT OK\n");
}


//------------------------------------------------------------------
// main()
//------------------------------------------------------------------
int main(void)
{
  check_modexp_access();
  //  tc_set_debug(1);

//  check_modulus_mem();
//  check_exponent_mem();
//  check_message_mem();

//  tc1();
//  tc2();
//  tc3();
//  tc4();
//  tc5();
//  tc6();
//  tc7();
//  tc8();
  rob_dec_1024();
  rob_enc_1024();

  return 0;
}

//======================================================================
// EOF modexp_tester.c
//======================================================================