/*************************************************************************** * Copyright (C) 2010 by Michael Fischer * * fischer-michael@cs.yale.edu * * * * For use in Yale course CPSC 467b, Spring 2010 * ***************************************************************************/ // Compute a^b (mod c) using openssl BN library // usage: modexp-ssl a b c #include #include #include #include "stopwatch.h" // ---------------------------------------------------------------------------- int main(int argc, char* argv[]) { stopwatch watch; if (argc != 4) { fprintf(stderr, "usage: %s a b c\n", argv[0]); return 1; } // Start timing startTime(&watch); BIGNUM* a = BN_new(); BIGNUM* b = BN_new(); BIGNUM* c = BN_new(); BIGNUM* d = BN_new(); int ret; ret = BN_dec2bn(&a, argv[1]); ret = BN_dec2bn(&b, argv[2]); ret = BN_dec2bn(&c, argv[3]); BN_CTX *ctx = BN_CTX_new(); ret = BN_mod_exp(d, a, b, c, ctx); BN_CTX_free(ctx); char* s; s = BN_bn2dec(d); puts(s); OPENSSL_free( s ); BN_free(a); BN_free(b); BN_free(c); BN_free(d); // Stop timing stopTime(&watch); // Print timing results printElapsedTime(&watch); }