diff options
-rw-r--r-- | networking/tls_sp_c32.c | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index 6fca2aad8..17fc05f63 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c | |||
@@ -291,10 +291,10 @@ static int sp_256_sub_8(sp_digit* r, const sp_digit* a, const sp_digit* b) | |||
291 | #endif | 291 | #endif |
292 | } | 292 | } |
293 | 293 | ||
294 | #if ALLOW_ASM && defined(__GNUC__) && defined(__i386__) | ||
294 | /* Sub p256_mod from a into r. (r = a - p256_mod). */ | 295 | /* Sub p256_mod from a into r. (r = a - p256_mod). */ |
295 | static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) | 296 | static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) |
296 | { | 297 | { |
297 | #if ALLOW_ASM && defined(__GNUC__) && defined(__i386__) | ||
298 | sp_digit reg; | 298 | sp_digit reg; |
299 | //p256_mod[7..0] = ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff | 299 | //p256_mod[7..0] = ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff |
300 | asm volatile ( | 300 | asm volatile ( |
@@ -334,30 +334,10 @@ static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) | |||
334 | : "0" (a), "1" (r) | 334 | : "0" (a), "1" (r) |
335 | : "memory" | 335 | : "memory" |
336 | ); | 336 | ); |
337 | } | ||
337 | #else | 338 | #else |
338 | const sp_digit* b = p256_mod; | 339 | # define sp_256_sub_8_p256_mod(r, a) sp_256_sub_8((r), (a), p256_mod) |
339 | int i; | ||
340 | sp_digit borrow; | ||
341 | |||
342 | borrow = 0; | ||
343 | for (i = 0; i < 8; i++) { | ||
344 | sp_digit w, v; | ||
345 | w = b[i] + borrow; | ||
346 | v = a[i]; | ||
347 | if (w != 0) { | ||
348 | v = a[i] - w; | ||
349 | borrow = (v > a[i]); | ||
350 | /* hope compiler detects above as "carry flag set" */ | ||
351 | } | ||
352 | /* else: b + borrow == 0, two cases: | ||
353 | * b:ffffffff, borrow:1 | ||
354 | * b:00000000, borrow:0 | ||
355 | * in either case, r[i] = a[i] and borrow remains unchanged | ||
356 | */ | ||
357 | r[i] = v; | ||
358 | } | ||
359 | #endif | 340 | #endif |
360 | } | ||
361 | 341 | ||
362 | /* Multiply a and b into r. (r = a * b) */ | 342 | /* Multiply a and b into r. (r = a * b) */ |
363 | static void sp_256_mul_8(sp_digit* r, const sp_digit* a, const sp_digit* b) | 343 | static void sp_256_mul_8(sp_digit* r, const sp_digit* a, const sp_digit* b) |