X-Git-Url: https://bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=src%2Fint%2Fi15_decode.c;fp=src%2Fec%2Fec_prime_i31_secp521r1.c;h=fc2c0be0d0be93705fb22c605436c9dd7d046eb3;hp=84d7d54f4679e7c579c5635154fb4a1e7a1c7599;hb=2f454aad577ae53798935cc32438a2d3f02ba31f;hpb=bd3036844bd20b2b8d7bce7fee5ad010ce401915;ds=inline diff --git a/src/ec/ec_prime_i31_secp521r1.c b/src/int/i15_decode.c similarity index 63% rename from src/ec/ec_prime_i31_secp521r1.c rename to src/int/i15_decode.c index 84d7d54..fc2c0be 100644 --- a/src/ec/ec_prime_i31_secp521r1.c +++ b/src/int/i15_decode.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Thomas Pornin + * Copyright (c) 2017 Thomas Pornin * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -24,27 +24,33 @@ #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); +}