Ver código fonte

Creating qstrings.c file, holding utilities for working with strings.

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.
Michele Orrù 11 anos atrás
pai
commit
3a220b7ff0

+ 1 - 8
src/questions/dixon.c

@@ -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 */

+ 21 - 0
src/questions/qstrings.c

@@ -0,0 +1,21 @@
+/**
+ * \file qstrings.c
+ *
+ * \brief Extend stdlib support with some common functions used in questions.
+ *
+ */
+#include "qstrings.h"
+
+
+/**
+ * \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;
+}

+ 8 - 0
src/questions/qstrings.h

@@ -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_ */

+ 20 - 0
src/questions/tests/test_qstrings.c

@@ -0,0 +1,20 @@
+#include <stddef.h>
+#include <assert.h>
+
+#include "qstrings.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;
+}