tweak, build.sh
[shamirs] / shamirssecret.c
index 66442953709a93ffa6a01db4e00863d860fc596d..be6eed3f9d0c4247dc09a6a7d27fa0f775a32396 100644 (file)
@@ -102,6 +102,11 @@ static uint8_t field_pow_ret(uint8_t calc, uint8_t a, uint8_t e) {
        return ret;
 }
 static uint8_t field_pow(uint8_t a, uint8_t e) {
+#ifndef TEST
+       // Although this function works for a==0, its not trivially obvious why,
+       // and since we never call with a==0, we just assert a != 0 (except when testing)
+       assert(a != 0);
+#endif
        return field_pow_ret(exp[(log[a] * e) % 255], a, e);
 }
 
@@ -125,7 +130,7 @@ static uint8_t field_mul_calc(uint8_t a, uint8_t b) {
 static uint8_t field_pow_calc(uint8_t a, uint8_t e) {
        uint8_t ret = 1;
        for (uint8_t i = 0; i < e; i++)
-               ret = field_mul(ret, a);
+               ret = field_mul_calc(ret, a);
        return ret;
 }
 int main() {
@@ -134,7 +139,7 @@ int main() {
                assert(field_mul_calc(i, field_invert(i)) == 1);
 
        // Test multiplication with the logarithm tables
-       for (uint16_t i = 0; i < 2; i++) {
+       for (uint16_t i = 0; i < P; i++) {
                for (uint16_t j = 0; j < P; j++)
                        assert(field_mul(i, j) == field_mul_calc(i, j));
        }
@@ -241,7 +246,7 @@ int main(int argc, char* argv[]) {
                        ERROREXIT("getopt failed?\n")
                }
        if (!(split & 0x2))
-               ERROREXIT("Must specify either -c or -s\n")
+               ERROREXIT("Must specify one of -c, -s or -?\n")
        split &= 0x1;
 
        if (argc != optind)
@@ -275,13 +280,16 @@ int main(int argc, char* argv[]) {
 
                uint8_t a[k], D[n][secret_length];
 
-               for (uint8_t i = 0; i < secret_length; i++) {
+               for (uint32_t i = 0; i < secret_length; i++) {
                        a[0] = secret[i];
 
                        for (uint8_t j = 1; j < k; j++)
                                assert(fread(&a[j], sizeof(uint8_t), 1, random) == 1);
                        for (uint8_t j = 0; j < n; j++)
                                D[j][i] = calculateQ(a, k, j+1);
+
+                       if (i % 32 == 0 && i != 0)
+                               printf("Finished processing %u bytes.\n", i);
                }
 
                char out_file_name_buf[strlen(out_file_param) + 4];
@@ -337,7 +345,7 @@ int main(int argc, char* argv[]) {
 
                uint8_t secret[MAX_LENGTH];
 
-               uint8_t i = 0;
+               uint32_t i = 0;
                while (fread(&q[0], sizeof(uint8_t), 1, files_fps[0]) == 1) {
                        for (uint8_t j = 1; j < k; j++) {
                                if (fread(&q[j], sizeof(uint8_t), 1, files_fps[j]) != 1)