summaryrefslogtreecommitdiff
path: root/assignment1/exercise1_2.c
diff options
context:
space:
mode:
authorDennis Brentjes <dennis@brentj.es>2016-02-29 16:51:52 +0100
committerDennis Brentjes <dennis@brentj.es>2016-02-29 16:51:52 +0100
commitbbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae (patch)
treed5c457c5516cbf17b6d58aaf4bb158b7e8c86241 /assignment1/exercise1_2.c
downloadcrypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.tar.gz
crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.tar.bz2
crypto-eng-bbcd3dff79a3fffafd8c4f5fdf30738c7117b8ae.zip
First commit with the first homework assignment.HEADmaster
Diffstat (limited to 'assignment1/exercise1_2.c')
-rw-r--r--assignment1/exercise1_2.c75
1 files changed, 75 insertions, 0 deletions
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;
+}