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

Subversion Repositories mod_sim_exp

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 28 to Rev 29
    Reverse comparison

Rev 28 → Rev 29

/mod_sim_exp/trunk/sw/ModMult/Release/ModMult.exe Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
mod_sim_exp/trunk/sw/ModMult/Release/ModMult.exe Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: mod_sim_exp/trunk/sw/ModMult/.project =================================================================== --- mod_sim_exp/trunk/sw/ModMult/.project (nonexistent) +++ mod_sim_exp/trunk/sw/ModMult/.project (revision 29) @@ -0,0 +1,26 @@ + + + ModMult + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + Index: mod_sim_exp/trunk/sw/ModMult/src/ModMult.c =================================================================== --- mod_sim_exp/trunk/sw/ModMult/src/ModMult.c (nonexistent) +++ mod_sim_exp/trunk/sw/ModMult/src/ModMult.c (revision 29) @@ -0,0 +1,70 @@ +/* + ============================================================================ + Name : ModExp.c + Author : + Version : + Copyright : Your copyright notice + Description : Hello World in C, Ansi-style + ============================================================================ + */ + +#include +#include +#include + +int main(void) { + unsigned int base_width; + mpz_t x, m, r, R, R2; + gmp_randstate_t state; + + gmp_randinit_mt(state); + mpz_init(x); + mpz_init(m); + mpz_init(r); + mpz_init(R); + mpz_init(R2); + + printf("-- input generator program\n"); + printf("-- generates test values for multiplier testbench\n"); + + while (1){ + + //read in base_width + scanf("%d", &base_width); + if (base_width == 0) break; + + //generate modulus (must be uneven) + mpz_urandomb(m, state, base_width); + mpz_setbit(m, 0); //uneven + + //generate x + mpz_urandomb(x, state, base_width); + + //calculate R + mpz_set_ui(R, 2); + mpz_powm_ui(R, R, base_width, m); //R = 2^n mod m + + //calculate R2 + mpz_set_ui(R2, 2); + mpz_powm(R2, R, R2, m); //R2 = Rē mod m = 2^2n mod m + + //calculate result + mpz_mul(r, x, R); + mpz_powm_ui(r, r, 1, m); + + printf("-- x, y, m, result\n"); + gmp_printf("%Zx\n", x); + gmp_printf("%Zx\n", R2); + gmp_printf("%Zx\n", m); + gmp_printf("%Zx\n", r); + } + + mpz_clear(x); + mpz_clear(R2); + mpz_clear(m); + mpz_clear(r); + mpz_clear(R); + gmp_randclear(state); + + return EXIT_SUCCESS; +} Index: mod_sim_exp/trunk/sw/ModMult/.cproject =================================================================== --- mod_sim_exp/trunk/sw/ModMult/.cproject (nonexistent) +++ mod_sim_exp/trunk/sw/ModMult/.cproject (revision 29) @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: mod_sim_exp/trunk/sw/ModMult/.settings/org.eclipse.cdt.managedbuilder.core.prefs =================================================================== --- mod_sim_exp/trunk/sw/ModMult/.settings/org.eclipse.cdt.managedbuilder.core.prefs (nonexistent) +++ mod_sim_exp/trunk/sw/ModMult/.settings/org.eclipse.cdt.managedbuilder.core.prefs (revision 29) @@ -0,0 +1,21 @@ +eclipse.preferences.version=1 +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.2041168883/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.2071011908/appendContributed=true Index: mod_sim_exp/trunk/sw/ModExp/Release/sim.txt =================================================================== --- mod_sim_exp/trunk/sw/ModExp/Release/sim.txt (nonexistent) +++ mod_sim_exp/trunk/sw/ModExp/Release/sim.txt (revision 29) @@ -0,0 +1,7 @@ +512 +32 +1024 +16 +1536 +16 +0 Index: mod_sim_exp/trunk/sw/ModExp/Release/ModExp.exe =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: mod_sim_exp/trunk/sw/ModExp/Release/ModExp.exe =================================================================== --- mod_sim_exp/trunk/sw/ModExp/Release/ModExp.exe (nonexistent) +++ mod_sim_exp/trunk/sw/ModExp/Release/ModExp.exe (revision 29)
mod_sim_exp/trunk/sw/ModExp/Release/ModExp.exe Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: mod_sim_exp/trunk/sw/ModExp/.project =================================================================== --- mod_sim_exp/trunk/sw/ModExp/.project (nonexistent) +++ mod_sim_exp/trunk/sw/ModExp/.project (revision 29) @@ -0,0 +1,26 @@ + + + ModExp + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + Index: mod_sim_exp/trunk/sw/ModExp/src/ModExp.c =================================================================== --- mod_sim_exp/trunk/sw/ModExp/src/ModExp.c (nonexistent) +++ mod_sim_exp/trunk/sw/ModExp/src/ModExp.c (revision 29) @@ -0,0 +1,113 @@ +/* + ============================================================================ + Name : ModExp.c + Author : + Version : + Copyright : Your copyright notice + Description : Hello World in C, Ansi-style + ============================================================================ + */ + +#include +#include +#include + +int main(void) { + unsigned int base_width, exp_width; + mpz_t m, g0, g1, e0, e1, R, R2, result, tmp, gt0, gt1, gt01; + gmp_randstate_t state; + + gmp_randinit_default(state); + mpz_init(m); + mpz_init(g0); + mpz_init(g1); + mpz_init(e0); + mpz_init(e1); + mpz_init(R); + mpz_init(R2); + mpz_init(result); + mpz_init(tmp); + mpz_init(gt0); + mpz_init(gt1); + mpz_init(gt01); + + printf("-- input generator program\n"); + printf("-- generates test values per bit input pair\n"); + + while (1){ + + //read in base_width + scanf("%d", &base_width); + if (base_width == 0) break; + scanf("%d", &exp_width); + + //generate modulus (must be uneven) + mpz_urandomb(m, state, base_width); + mpz_setbit(m, 0); //uneven + + //generate g0 + mpz_urandomb(g0, state, base_width); + + //generate g1 + mpz_urandomb(g1, state, base_width); + + //generate e0 + mpz_urandomb(e0, state, exp_width); + + //generate e1 + mpz_urandomb(e1, state, exp_width); + + //calculate R + mpz_set_ui(R, 2); + mpz_powm_ui(R, R, base_width, m); //R = 2^n mod m + + //calculate R2 + mpz_set_ui(R2, 2); + mpz_powm(R2, R, R2, m); //R2 = Rē mod m = 2^2n mod m + + //calc precompute values + mpz_mul(gt0, g0, R); + mpz_powm_ui(gt0, gt0, 1, m); + mpz_mul(gt1, g1, R); + mpz_powm_ui(gt1, gt1, 1, m); + mpz_mul(gt01, g0, g1); + mpz_mul(gt01, gt01, R); + mpz_powm_ui(gt01, gt01, 1, m); + + //calculate result + mpz_powm(result, g0, e0, m); + mpz_powm(tmp, g1, e1, m); + mpz_mul(result, result, tmp); + mpz_powm_ui(result, result, 1, m); + + printf("-- base_width, exp_width, g0, g1, e0, e1, m, R^2, result\n"); + printf("%d\n", base_width); + printf("%d\n", exp_width); + gmp_printf("%Zx\n", g0); + gmp_printf("%Zx\n", g1); + gmp_printf("%Zx\n", e0); + gmp_printf("%Zx\n", e1); + gmp_printf("%Zx\n", m); + gmp_printf("%Zx\n", R2); + gmp_printf("%Zx\n", R); + gmp_printf("%Zx\n", gt0); + gmp_printf("%Zx\n", gt1); + gmp_printf("%Zx\n", gt01); + gmp_printf("%Zx\n", result); + } + + mpz_clear(g0); + mpz_clear(g1); + mpz_clear(e0); + mpz_clear(e1); + mpz_clear(m); + mpz_clear(result); + mpz_clear(tmp); + mpz_clear(R); + mpz_clear(R2); + mpz_clear(gt0); + mpz_clear(gt1); + mpz_clear(gt01); + + return EXIT_SUCCESS; +} Index: mod_sim_exp/trunk/sw/ModExp/.cproject =================================================================== --- mod_sim_exp/trunk/sw/ModExp/.cproject (nonexistent) +++ mod_sim_exp/trunk/sw/ModExp/.cproject (revision 29) @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: mod_sim_exp/trunk/sw/ModExp/.settings/org.eclipse.cdt.managedbuilder.core.prefs =================================================================== --- mod_sim_exp/trunk/sw/ModExp/.settings/org.eclipse.cdt.managedbuilder.core.prefs (nonexistent) +++ mod_sim_exp/trunk/sw/ModExp/.settings/org.eclipse.cdt.managedbuilder.core.prefs (revision 29) @@ -0,0 +1,21 @@ +eclipse.preferences.version=1 +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.231013975/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.release.725964274/appendContributed=true

powered by: WebSVN 2.1.0

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