First step torwars a include "qa/questions/foo.h". Moving is_vzero() from Dixon into another file, which could be used as well for other attacks.
@@ -23,6 +23,7 @@
#include <openssl/bn.h>
#include "qarith.h"
+#include "qstrings.h"
#include "questions.h"
#define EPOCHS 100
@@ -180,14 +181,6 @@ int dixon_question_test(X509* cert) {
}
-static int is_vzero(void *v, size_t len)
-{
- char unsigned *s = (char unsigned *) v;
- while (len--)
- if (*(s++)) return 0;
- return 1;
-}
-
int dixon_question_ask(X509* cert) {
RSA *rsa;
/* key data */
@@ -0,0 +1,21 @@
+/**
+ * \file qstrings.c
+ *
+ * \brief Extend stdlib support with some common functions used in questions.
+ */
+
+ * \brief Check v the first len bits of v are filled with zeroes
+ * \return true if the first len bits of v are zero, false otherwise.
+int is_vzero(const void *v, size_t len)
+{
+ char unsigned *s = (char unsigned *) v;
+ while (len--)
+ if (*(s++)) return 0;
+ return 1;
+}
@@ -0,0 +1,8 @@
+#ifndef _QA_QSTRINGS_H_
+#define _QA_QSTRINGS_H_
+#include <stddef.h>
+int is_vzero(const void *v, size_t len);
+#endif /* _QA_QSTRINGS_H_ */
@@ -0,0 +1,20 @@
+#include <assert.h>
+void test_is_vzero(void)
+ const char *v = "\x0\x0\x0\x1\x0\x1";
+ assert(is_vzero(v, 3));
+ assert(!is_vzero(v, 4));
+ assert(!is_vzero(v, 6));
+int main(int argc, char **argv)
+ test_is_vzero();
+ return 0;