/*
- * 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
#include "inner.h"
-static const uint32_t P521_P[] = {
- 0x00000219,
- 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF,
- 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF,
- 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF,
- 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF,
- 0x01FFFFFF
-};
+/* see inner.h */
+void
+br_i15_decode(uint16_t *x, const void *src, size_t len)
+{
+ const unsigned char *buf;
+ size_t v;
+ uint32_t acc;
+ int acc_len;
-static const uint32_t P521_B[] = {
- 0x00000219,
- 0x540FC00A, 0x228FEA35, 0x2C34F1EF, 0x67BF107A,
- 0x46FC1CD5, 0x1605E9DD, 0x6937B165, 0x272A3D8F,
- 0x42785586, 0x44C8C778, 0x15F3B8B4, 0x64B73366,
- 0x03BA8B69, 0x0D05B42A, 0x21F929A2, 0x2C31C393,
- 0x00654FAE
-};
+ buf = src;
+ v = 1;
+ acc = 0;
+ acc_len = 0;
+ while (len -- > 0) {
+ uint32_t b;
-/* see inner.h */
-const br_ec_prime_i31_curve br_ec_prime_i31_secp521r1 = {
- P521_P,
- P521_B,
- 0x00000001
-};
+ b = buf[len];
+ acc |= (b << acc_len);
+ acc_len += 8;
+ if (acc_len >= 15) {
+ x[v ++] = acc & 0x7FFF;
+ acc_len -= 15;
+ acc >>= 15;
+ }
+ }
+ if (acc_len != 0) {
+ x[v ++] = acc;
+ }
+ x[0] = br_i15_bit_length(x + 1, v - 1);
+}