All done except 1
[sws1-1415.git] / ass3 / mart / sws1-assignment3-s4109503-s4202015 / exercise2.c
index 30ab2a4..c5f22bb 100644 (file)
@@ -1,12 +1,14 @@
 #include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
 
 typedef unsigned char uc;
 typedef unsigned __int128 uint128;
 
 void addvector(int *r, const int *a, const int *b, size_t len)
 {
-       for(int *r2 = r; r2 < r + len;r2++, a++, b++)
-               *r2 = *a + *b;
+       for(int *r2 = r; r2 < r + len; r2++)
+               *r2 = *a++ + *b++;
 }
 
 int memcmp(const void *s1, const void *s2, size_t n)
@@ -35,3 +37,12 @@ int memcmp_fast(const void *s1, const void *s2, size_t n)
                        return memcmp(s3, s4, sizeof(uint128));
        return memcmp(s3, s4, n % sizeof(uint128));
 }
+
+int memcmp_consttime(const void *s1, const void *s2, size_t n)
+{
+       int returnvalue = 0;
+       for(uc *s3 = (uc*)s1, *s4 = (uc*)s2; s3 < (uc*)s1 + n; s3++, s4++)
+               if(*s3 != *s4 && returnvalue == 0)
+                       returnvalue = *s3 - *s4;
+       return returnvalue;
+}