From 502f0f429a261628fe5e43582280012541c40804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 24 Apr 2015 15:16:23 +0200 Subject: (1) Adding auto generated testbench for verilog. (2) Update of the test generator. (3) Update of the Makefile to run test generator. --- src/model/c/src/simple_tests.c | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/model/c/src/simple_tests.c (limited to 'src/model/c/src/simple_tests.c') diff --git a/src/model/c/src/simple_tests.c b/src/model/c/src/simple_tests.c new file mode 100644 index 0000000..402a8ac --- /dev/null +++ b/src/model/c/src/simple_tests.c @@ -0,0 +1,72 @@ +//====================================================================== +// +// simple_tests.h +// -------------- +// Header fil to export the simple tests of the modexp C model. +// +// +// Author: Joachim Strombergson +// Copyright (c) 2015, Assured AB +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the following +// conditions are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. 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. +// +// 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 OWNER 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 +#include +#include "montgomery_array.h" +#include "bignum_uint32_t.h" + +void simple_3_7_11(void) { + printf("=== Simple test with X = 3, E = 7 and M = 11 ===\n"); + uint32_t X[] = { 0x3 }; + uint32_t E[] = { 0x7 }; + uint32_t M[] = { 0xb }; + uint32_t expected[] = { 0x9 }; + uint32_t Z[] = { 0x00000000 }; + mod_exp_array(1, X, E, M, Z); + assertArrayEquals(1, expected, Z); +} + +void simple_251_251_257(void) { + printf("=== Simple test with X = 251, E = 251 and M = 257 ===\n"); + uint32_t X[] = { 0xfb }; + uint32_t E[] = { 0xfb }; + uint32_t M[] = { 0x101 }; + uint32_t expected[] = { 0xb7 }; + uint32_t Z[] = { 0x00000000 }; + mod_exp_array(1, X, E, M, Z); + assertArrayEquals(1, expected, Z); +} + +void simple_tests(void) { + simple_3_7_11(); + simple_251_251_257(); +} + +//====================================================================== +// EOF simple_tests.h +//====================================================================== -- cgit v1.2.3