diff options
| author | Dennis Brentjes <dennis@brentj.es> | 2016-02-29 16:51:52 +0100 |
|---|---|---|
| committer | Dennis Brentjes <dennis@brentj.es> | 2016-02-29 16:51:52 +0100 |
| commit | bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae (patch) | |
| tree | d5c457c5516cbf17b6d58aaf4bb158b7e8c86241 /assignment1/exercise1_1.c | |
| download | crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.tar.gz crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.tar.bz2 crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.zip | |
Diffstat (limited to 'assignment1/exercise1_1.c')
| -rw-r--r-- | assignment1/exercise1_1.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/assignment1/exercise1_1.c b/assignment1/exercise1_1.c new file mode 100644 index 0000000..e1dd810 --- /dev/null +++ b/assignment1/exercise1_1.c @@ -0,0 +1,33 @@ +#include <stdint.h> +#include <stdio.h> + +uint32_t modexp(uint32_t a, unsigned char e[4]) +{ + /* TODO: implement */ +} + +/* Pipe output through sage */ +#define NTESTS 20 +int main(void) +{ + FILE *urandom = fopen("/dev/urandom", "r"); + uint32_t a,r,ei; + unsigned char e[4]; + int i,j; + + for(i=0;i<NTESTS;i++) + { + fread(&a,sizeof(uint32_t),1,urandom); + fread(e,sizeof(unsigned char),4,urandom); + r = modexp(a,e); + + ei = 0; + for(j=0;j<4;j++) + ei |= (uint32_t)e[j] << 8*j; + + printf("power_mod(%u,%u,2^32) - %u\n", a,ei,r); + } + + fclose(urandom); + return 0; +} |
