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 | |
| download | crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.tar.gz crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.tar.bz2 crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.zip | |
| -rw-r--r-- | assignment1/2016_assignment1.pdf | bin | 0 -> 98565 bytes | |||
| -rw-r--r-- | assignment1/exercise1_1.c | 33 | ||||
| -rw-r--r-- | assignment1/exercise1_2.c | 75 |
3 files changed, 108 insertions, 0 deletions
diff --git a/assignment1/2016_assignment1.pdf b/assignment1/2016_assignment1.pdf Binary files differnew file mode 100644 index 0000000..a5be064 --- /dev/null +++ b/assignment1/2016_assignment1.pdf 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; +} diff --git a/assignment1/exercise1_2.c b/assignment1/exercise1_2.c new file mode 100644 index 0000000..fea4230 --- /dev/null +++ b/assignment1/exercise1_2.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <string.h> +#include <inttypes.h> + +typedef unsigned char poly8; +typedef unsigned long long poly8x64[8]; + +void poly8_bitslice(poly8x64 r, const poly8 x[64]) +{ + /* TODO implement */ +} + +/* reduction polynomial x^8 + x^4 + x^3 + x + 1 */ +void poly8x64_mulmod(poly8x64 r, const poly8x64 a, const poly8x64 b) +{ + /* TODO implement */ +} + +void poly8x64_unbitslice(poly8 r[64], const poly8x64 x) +{ + /* TODO implement */ +} + +static void poly8mod_print(const poly8 x) +{ + int i; + int d=0; + printf("Mod("); + for(i=0;i<8;i++) + if(1&(x>>i)) + { + if(d) printf(" + "); + printf("Mod(1,2)*X^%d",i); + d = 1; + } + if(d==0) printf("Mod(0,2)"); + printf(",Mod(1,2)*X^8+Mod(1,2)*X^4+Mod(1,2)*X^3+Mod(1,2)*X+Mod(1,2))"); +} + + +/* Pipe output through gp */ +int main() +{ + + poly8 a[64], b[64], r[64]; + poly8x64 va, vb, vt; + int i; + + FILE *urandom = fopen("/dev/urandom","r"); + for(i=0;i<64;i++) + { + a[i] = fgetc(urandom); + b[i] = fgetc(urandom); + } + + poly8_bitslice(va, a); + poly8_bitslice(vb, b); + + poly8x64_mulmod(vt,va,vb); + poly8x64_unbitslice(r,vt); + + for(i=0;i<64;i++) + { + printf("centerlift(centerlift("); + poly8mod_print(a[i]); + printf(" * "); + poly8mod_print(b[i]); + printf(" - "); + poly8mod_print(r[i]); + printf("))\n"); + } + + fclose(urandom); + return 0; +} |
