Some cleanups (removed unused files, split i15 code into per-function files).
[BearSSL] / src / int / i15_add.c
similarity index 70%
rename from src/ec/ec_prime_i31_secp256r1.c
rename to src/int/i15_add.c
index 007b6b2..97e29b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
+ * Copyright (c) 2017 Thomas Pornin <pornin@bolet.org>
  *
  * Permission is hereby granted, free of charge, to any person obtaining 
  * a copy of this software and associated documentation files (the
  *
  * Permission is hereby granted, free of charge, to any person obtaining 
  * a copy of this software and associated documentation files (the
 
 #include "inner.h"
 
 
 #include "inner.h"
 
-static const uint32_t P256_P[] = {
-       0x00000108,
-       0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x00000007,
-       0x00000000, 0x00000000, 0x00000040, 0x7FFFFF80,
-       0x000000FF
-};
+/* see inner.h */
+uint32_t
+br_i15_add(uint16_t *a, const uint16_t *b, uint32_t ctl)
+{
+       uint32_t cc;
+       size_t u, m;
 
 
-static const uint32_t P256_B[] = {
-       0x00000108,
-       0x6FEE1803, 0x6229C4BD, 0x21B139BE, 0x327150AA,
-       0x3567802E, 0x3F7212ED, 0x012E4355, 0x782DD38D,
-       0x0000000E
-};
+       cc = 0;
+       m = (a[0] + 31) >> 4;
+       for (u = 1; u < m; u ++) {
+               uint32_t aw, bw, naw;
 
 
-/* see inner.h */
-const br_ec_prime_i31_curve br_ec_prime_i31_secp256r1 = {
-       P256_P,
-       P256_B,
-       0x00000001
-};
+               aw = a[u];
+               bw = b[u];
+               naw = aw + bw + cc;
+               cc = naw >> 15;
+               a[u] = MUX(ctl, naw & 0x7FFF, aw);
+       }
+       return cc;
+}