#include "power_clocks_lib.h"
#include "gpio.h"
#include "intc.h"
#include "print_funcs.h"
#include "nlao_cpu.h"
#include "nlao_usart.h"
#include <string.h>
#include <stdlib.h>
#include "cycle_counter.h"
#include "polarssl/config.h"
#include "polarssl/md4.h"
#include "polarssl/md5.h"
#include "polarssl/sha1.h"
#include "polarssl/sha2.h"
#include "polarssl/sha4.h"
#include "polarssl/arc4.h"
#include "polarssl/des.h"
#include "polarssl/aes.h"
#include "polarssl/camellia.h"
#include "polarssl/rsa.h"
#include "polarssl/timing.h"
Go to the source code of this file.
Defines | |
#define | _CRT_SECURE_NO_DEPRECATE 1 |
#define | BUFSIZE 1024 |
Functions | |
int | _init_startup (void) |
Low-level initialization routine called during startup, before the main function. | |
static void | init_sys_clocks (void) |
Initializes the MCU system clocks. | |
int | main (void) |
static int | myrand (void *rng_state) |
Variables | |
unsigned char | buf [BUFSIZE] |
System Clock Frequencies | |
static pcl_freq_param_t | pcl_freq_param |
#define _CRT_SECURE_NO_DEPRECATE 1 |
Definition at line 25 of file benchmark.c.
#define BUFSIZE 1024 |
int _init_startup | ( | void | ) |
Low-level initialization routine called during startup, before the main function.
This version comes in replacement to the default one provided by the Newlib add-ons library. Newlib add-ons' _init_startup only calls init_exceptions, but Newlib add-ons' exception and interrupt vectors are defined in the same section and Newlib add-ons' interrupt vectors are not compatible with the interrupt management of the INTC module. More low-level initializations are besides added here.
Definition at line 99 of file benchmark.c.
References pcl_freq_param.
00100 { 00101 // Import the Exception Vector Base Address. 00102 extern void _evba; 00103 00104 // Load the Exception Vector Base Address in the corresponding system register. 00105 Set_system_register(AVR32_EVBA, (int)&_evba); 00106 00107 // Enable exceptions. 00108 Enable_global_exception(); 00109 00110 // Initialize interrupt handling. 00111 INTC_init_interrupts(); 00112 00113 // Give the used CPU clock frequency to Newlib, so it can work properly. 00114 set_cpu_hz(pcl_freq_param.pba_f); 00115 00116 // Initialize the USART used for the debug trace with the configured parameters. 00117 set_usart_base( ( void * ) DBG_USART ); 00118 00119 // Don't-care value for GCC. 00120 return 1; 00121 }
static void init_sys_clocks | ( | void | ) | [static] |
Initializes the MCU system clocks.
Definition at line 74 of file benchmark.c.
References pcl_freq_param.
Referenced by main().
00075 { 00076 00077 // Configure system clocks. 00078 if (pcl_configure_clocks(&pcl_freq_param) != PASS) { 00079 while(1); 00080 } 00081 00082 // Initialize usart comm 00083 init_dbg_rs232(pcl_freq_param.pba_f); 00084 }
int main | ( | void | ) |
Definition at line 158 of file benchmark.c.
References aes_crypt_cbc(), AES_ENCRYPT, aes_setkey_enc(), arc4_crypt(), arc4_setup(), buf, BUFSIZE, camellia_crypt_cbc(), CAMELLIA_ENCRYPT, camellia_setkey_enc(), des3_crypt_cbc(), des3_set3key_enc(), des_crypt_cbc(), DES_ENCRYPT, des_setkey_enc(), hardclock(), init_sys_clocks(), md4(), md5(), myrand(), rsa_free(), rsa_gen_key(), rsa_init(), RSA_PKCS_V15, rsa_private(), rsa_public(), sha1(), sha2(), and sha4().
00159 { 00160 int keysize; 00161 unsigned long i, j, tsc; 00162 unsigned char tmp[64]; 00163 t_cpu_time timer; 00164 00165 init_sys_clocks(); 00166 00167 printf( "Start Benchmark\n"); 00168 00169 #if defined(POLARSSL_ARC4_C) 00170 arc4_context arc4; 00171 #endif 00172 #if defined(POLARSSL_DES_C) 00173 des3_context des3; 00174 des_context des; 00175 #endif 00176 #if defined(POLARSSL_AES_C) 00177 aes_context aes; 00178 #endif 00179 #if defined(POLARSSL_CAMELLIA_C) 00180 camellia_context camellia; 00181 #endif 00182 #if defined(POLARSSL_RSA_C) 00183 rsa_context rsa; 00184 #endif 00185 00186 memset( buf, 0xAA, sizeof( buf ) ); 00187 00188 printf( "\n" ); 00189 00190 #if defined(POLARSSL_MD4_C) 00191 printf( " MD4 : " ); 00192 fflush( stdout ); 00193 00194 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00195 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00196 md4( buf, BUFSIZE, tmp ); 00197 00198 tsc = hardclock(); 00199 for( j = 0; j < 1024; j++ ) 00200 md4( buf, BUFSIZE, tmp ); 00201 00202 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00203 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00204 #endif 00205 00206 #if defined(POLARSSL_MD5_C) 00207 printf( " MD5 : " ); 00208 fflush( stdout ); 00209 00210 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00211 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00212 md5( buf, BUFSIZE, tmp ); 00213 00214 tsc = hardclock(); 00215 for( j = 0; j < 1024; j++ ) 00216 md5( buf, BUFSIZE, tmp ); 00217 00218 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00219 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00220 #endif 00221 00222 #if defined(POLARSSL_SHA1_C) 00223 printf( " SHA-1 : " ); 00224 fflush( stdout ); 00225 00226 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00227 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00228 sha1( buf, BUFSIZE, tmp ); 00229 00230 tsc = hardclock(); 00231 for( j = 0; j < 1024; j++ ) 00232 sha1( buf, BUFSIZE, tmp ); 00233 00234 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00235 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00236 #endif 00237 00238 #if defined(POLARSSL_SHA2_C) 00239 printf( " SHA-256 : " ); 00240 fflush( stdout ); 00241 00242 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00243 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00244 sha2( buf, BUFSIZE, tmp, 0 ); 00245 00246 tsc = hardclock(); 00247 for( j = 0; j < 1024; j++ ) 00248 sha2( buf, BUFSIZE, tmp, 0 ); 00249 00250 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00251 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00252 #endif 00253 00254 #if defined(POLARSSL_SHA4_C) 00255 printf( " SHA-512 : " ); 00256 fflush( stdout ); 00257 00258 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00259 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00260 sha4( buf, BUFSIZE, tmp, 0 ); 00261 00262 tsc = hardclock(); 00263 for( j = 0; j < 1024; j++ ) 00264 sha4( buf, BUFSIZE, tmp, 0 ); 00265 00266 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00267 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00268 #endif 00269 00270 #if defined(POLARSSL_ARC4_C) 00271 printf( " ARC4 : " ); 00272 fflush( stdout ); 00273 00274 arc4_setup( &arc4, tmp, 32 ); 00275 00276 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00277 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00278 arc4_crypt( &arc4, buf, BUFSIZE ); 00279 00280 tsc = hardclock(); 00281 for( j = 0; j < 1024; j++ ) 00282 arc4_crypt( &arc4, buf, BUFSIZE ); 00283 00284 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00285 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00286 #endif 00287 00288 #if defined(POLARSSL_DES_C) 00289 printf( " 3DES : " ); 00290 fflush( stdout ); 00291 00292 des3_set3key_enc( &des3, tmp ); 00293 00294 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00295 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00296 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00297 00298 tsc = hardclock(); 00299 for( j = 0; j < 1024; j++ ) 00300 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00301 00302 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00303 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00304 00305 printf( " DES : " ); 00306 fflush( stdout ); 00307 00308 des_setkey_enc( &des, tmp ); 00309 00310 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00311 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00312 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00313 00314 tsc = hardclock(); 00315 for( j = 0; j < 1024; j++ ) 00316 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00317 00318 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00319 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00320 #endif 00321 00322 #if defined(POLARSSL_AES_C) 00323 for( keysize = 128; keysize <= 256; keysize += 64 ) 00324 { 00325 printf( " AES-%d : ", keysize ); 00326 fflush( stdout ); 00327 00328 memset( buf, 0, sizeof( buf ) ); 00329 memset( tmp, 0, sizeof( tmp ) ); 00330 aes_setkey_enc( &aes, tmp, keysize ); 00331 00332 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00333 00334 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00335 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00336 00337 tsc = hardclock(); 00338 for( j = 0; j < 4096; j++ ) 00339 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00340 00341 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00342 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00343 } 00344 #endif 00345 00346 #if defined(POLARSSL_CAMELLIA_C) 00347 for( keysize = 128; keysize <= 256; keysize += 64 ) 00348 { 00349 printf( " CAMELLIA-%d : ", keysize ); 00350 fflush( stdout ); 00351 00352 memset( buf, 0, sizeof( buf ) ); 00353 memset( tmp, 0, sizeof( tmp ) ); 00354 camellia_setkey_enc( &camellia, tmp, keysize ); 00355 00356 cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); 00357 00358 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00359 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00360 00361 tsc = hardclock(); 00362 for( j = 0; j < 4096; j++ ) 00363 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ); 00364 00365 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, 00366 ( hardclock() - tsc ) / ( j * BUFSIZE ) ); 00367 } 00368 #endif 00369 00370 #if defined(POLARSSL_RSA_C) 00371 rsa_init( &rsa, RSA_PKCS_V15, 0, myrand, NULL ); 00372 rsa_gen_key( &rsa, 1024, 65537 ); 00373 00374 printf( " RSA-1024 : " ); 00375 fflush( stdout ); 00376 cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); 00377 00378 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00379 { 00380 buf[0] = 0; 00381 rsa_public( &rsa, buf, buf ); 00382 } 00383 00384 printf( "%9lu public/s\n", i / 3 ); 00385 00386 printf( " RSA-1024 : " ); 00387 fflush( stdout ); 00388 cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); 00389 00390 for( i = 1; !cpu_is_timeout(&timer); i++ ) 00391 { 00392 buf[0] = 0; 00393 rsa_private( &rsa, buf, buf ); 00394 } 00395 00396 printf( "%9lu private/s\n\n", i / 3 ); 00397 00398 rsa_free( &rsa ); 00399 #endif 00400 00401 #ifdef WIN32 00402 printf( " Press Enter to exit this program.\n" ); 00403 fflush( stdout ); getchar(); 00404 #endif 00405 00406 return( 0 ); 00407 }
static int myrand | ( | void * | rng_state | ) | [static] |
unsigned char buf[BUFSIZE] |
pcl_freq_param_t pcl_freq_param [static] |
Initial value:
{ .cpu_f = AVR32_PM_CPU_MAX_FREQ, .pba_f = AVR32_PM_PBA_MAX_FREQ, .osc0_f = FOSC0, .osc0_startup = OSC0_STARTUP }
Definition at line 63 of file benchmark.c.
Referenced by _init_startup(), and init_sys_clocks().