diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1999-04-19 19:56:24 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1999-04-19 19:56:24 +0000 |
commit | 230bd89c7b66900b76cc34a000c1f8fd76dadf41 (patch) | |
tree | 374c4154777c9d8621c18f4be64a0a445f7217e5 /sbin | |
parent | c565a853e3766550f5381b1252355628bf9ee5c9 (diff) |
./math_2n.h: Merge with EOM 1.9
Style. alloc error reporting. Math error propagation. Allocate right
sizes.
1999
Style police. No free(0).
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/isakmpd/math_2n.h | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/sbin/isakmpd/math_2n.h b/sbin/isakmpd/math_2n.h index 13ee442ed98..93f21cda946 100644 --- a/sbin/isakmpd/math_2n.h +++ b/sbin/isakmpd/math_2n.h @@ -1,8 +1,9 @@ -/* $OpenBSD: math_2n.h,v 1.3 1998/11/17 11:10:16 niklas Exp $ */ -/* $EOM: math_2n.h,v 1.6 1998/07/18 21:09:40 provos Exp $ */ +/* $OpenBSD: math_2n.h,v 1.4 1999/04/19 19:56:23 niklas Exp $ */ +/* $EOM: math_2n.h,v 1.9 1999/04/17 23:20:32 niklas Exp $ */ /* * Copyright (c) 1998 Niels Provos. All rights reserved. + * Copyright (c) 1999 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,67 +69,69 @@ extern CHUNK_TYPE b2n_mask[CHUNK_BITS]; /* An element of GF(2**n), n = bits */ typedef struct { - u_int16_t chunks; - u_int16_t bits; - u_int8_t dirty; /* Sig bits are dirty */ - CHUNK_TYPE *limp; + u_int16_t chunks; + u_int16_t bits; + u_int8_t dirty; /* Sig bits are dirty */ + CHUNK_TYPE *limp; } _b2n; typedef _b2n *b2n_ptr; typedef _b2n b2n_t[1]; -#define B2N_SET(x,y) (x)->chunks = (y)->chunks; (x)->bits = (y)->bits; \ - (x)->limp = (y)->limp; (x)->dirty = (y)->dirty; +#define B2N_SET(x,y) do \ + { \ + (x)->chunks = (y)->chunks; \ + (x)->bits = (y)->bits; \ + (x)->limp = (y)->limp; \ + (x)->dirty = (y)->dirty; \ + } \ +while (0) + +#define B2N_SWAP(x,y) do \ + { \ + b2n_t _t_; \ +\ + B2N_SET (_t_, (x)); \ + B2N_SET ((x), (y)); \ + B2N_SET ((y), _t_); \ + } \ +while (0) #define B2N_MIN(x,y) ((x)->chunks > (y)->chunks ? (y) : (x)) #define B2N_MAX(x,y) ((x)->chunks > (y)->chunks ? (x) : (y)) +int b2n_3mul (b2n_ptr, b2n_ptr); +int b2n_add (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_cmp (b2n_ptr, b2n_ptr); +int b2n_cmp_null (b2n_ptr); +int b2n_div (b2n_ptr, b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_div_mod (b2n_ptr, b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_div_q (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_div_r (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_exp_mod (b2n_ptr, b2n_ptr, u_int32_t, b2n_ptr); void b2n_init (b2n_ptr); void b2n_clear (b2n_ptr); -void b2n_resize (b2n_ptr, unsigned int); - -void b2n_random (b2n_ptr, u_int32_t); - -void b2n_set (b2n_ptr, b2n_ptr); -void b2n_set_null (b2n_ptr); -void b2n_set_ui (b2n_ptr, unsigned int); -void b2n_set_str (b2n_ptr, char *); - +int b2n_gcd (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_halftrace (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_lshift (b2n_ptr, b2n_ptr, unsigned int); +int b2n_mod (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_mul (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_mul_inv (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_nadd (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_nsub (b2n_ptr, b2n_ptr, b2n_ptr); void b2n_print (b2n_ptr); +int b2n_random (b2n_ptr, u_int32_t); +int b2n_resize (b2n_ptr, unsigned int); +int b2n_rshift (b2n_ptr, b2n_ptr, unsigned int); +int b2n_set (b2n_ptr, b2n_ptr); +int b2n_set_null (b2n_ptr); +int b2n_set_str (b2n_ptr, char *); +int b2n_set_ui (b2n_ptr, unsigned int); +u_int32_t b2n_sigbit (b2n_ptr); int b2n_sprint (char *, b2n_ptr); - -int b2n_cmp (b2n_ptr, b2n_ptr); -int b2n_cmp_null (b2n_ptr); - -void b2n_add (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_sqrt (b2n_ptr, b2n_ptr, b2n_ptr); +int b2n_square (b2n_ptr, b2n_ptr); #define b2n_sub b2n_add -void b2n_lshift (b2n_ptr, b2n_ptr, unsigned int); -void b2n_rshift (b2n_ptr, b2n_ptr, unsigned int); -u_int32_t b2n_sigbit (b2n_ptr); - -void b2n_nadd (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_nsub (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_3mul (b2n_ptr, b2n_ptr); - -void b2n_mul (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_square (b2n_ptr, b2n_ptr); - -void b2n_div (b2n_ptr, b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_div_q (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_div_r (b2n_ptr, b2n_ptr, b2n_ptr); - -/* Operation on GF(2**n) */ -#define B2N_SWAP(x,y) {b2n_t _t_; B2N_SET(_t_, (x)); \ - B2N_SET ((x), (y)); B2N_SET ((y),_t_); } - -void b2n_mod (b2n_ptr, b2n_ptr, b2n_ptr); - -void b2n_gcd (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_mul_inv (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_div_mod (b2n_ptr, b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_trace (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_halftrace (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_sqrt (b2n_ptr, b2n_ptr, b2n_ptr); -void b2n_exp_mod (b2n_ptr, b2n_ptr, u_int32_t, b2n_ptr); +int b2n_trace (b2n_ptr, b2n_ptr, b2n_ptr); #endif /* _MATH_2N_H_ */ |