Lines Matching full:in1
23 * o out = in1 +/- in2 if cnd is not zero.
24 * o out = in1 if cnd is zero.
27 * constant time for that specific factor, nor on the values of in1 and in2.
28 * It still depends on the maximal length of in1 and in2.
35 * Conditionally adds 'in2' to 'in1' according to "cnd", storing the result
41 * commutative, i.e. "_nn_cnd_add(cnd, out, in1, in2)" is not equivalent
42 * to "_nn_cnd_add(cnd, out, in2, in1)". It is commutative though if "cnd"
43 * is not zero or 'in1' == 'in2'.
46 * that is if not aliased to 'in1' or 'in2'. The length of "out" is set to
47 * the maximal length of 'in1' and 'in2'. Note that both 'in1' and 'in2' will
54 * o the data stored in 'in1' and 'in2'.
56 * o the maximal length of 'in1' and 'in2'.
60 ATTRIBUTE_WARN_UNUSED_RET static int _nn_cnd_add(int cnd, nn_t out, nn_src_t in1, nn_src_t in2, in _nn_cnd_add() argument
69 ret = nn_check_initialized(in1); EG(ret, err); in _nn_cnd_add()
73 loop_wlen = LOCAL_MAX(in1->wlen, in2->wlen); in _nn_cnd_add()
74 if ((out != in1) && (out != in2)) { in _nn_cnd_add()
82 tmp = (word_t)(in1->val[i] + (in2->val[i] & mask)); in _nn_cnd_add()
83 carry1 = (word_t)(tmp < in1->val[i]); in _nn_cnd_add()
97 * Conditionally adds 'in2' to 'in1' according to "cnd", storing the result
99 * length of 'in1' and 'in2'. It is user responsibility to ensure that the
101 * for instance guaranteed if both in1->wlen and in2->wlen are less than
119 int nn_cnd_add(int cnd, nn_t out, nn_src_t in1, nn_src_t in2) in nn_cnd_add() argument
124 ret = _nn_cnd_add(cnd, out, in1, in2, &carry); EG(ret, err); in nn_cnd_add()
146 * Unconditionally adds 'in2' to 'in1', storing the result in "out",
148 * 'in1' and 'in2'. The function returns 0 on success, -1 on error.
158 int nn_add(nn_t out, nn_src_t in1, nn_src_t in2) in nn_add() argument
160 return nn_cnd_add(1, out, in1, in2); in nn_add()
164 * Compute out = in1 + w where 'in1' is an initialized nn and 'w' a word. It is
166 * for instance guaranteed if 'in1' wlen is less than NN_MAX_WORD_LEN). The
179 ATTRIBUTE_WARN_UNUSED_RET static int nn_add_word(nn_t out, nn_src_t in1, word_t w) in nn_add_word() argument
185 ret = nn_check_initialized(in1); EG(ret, err); in nn_add_word()
188 n_wlen = in1->wlen; in nn_add_word()
189 if (out != in1) { in nn_add_word()
198 tmp = (word_t)(in1->val[i] + carry); in nn_add_word()
199 carry = (word_t)(tmp < in1->val[i]); in nn_add_word()
221 * Compute out = in1 + 1. Aliasing is supported i.e. nn_inc(in1, in1) works as
222 * expected and provides in1++. It is caller responsibility to ensure that the
223 * result will fit in a nn (This is for instance guaranteed if 'in1' wlen is
231 int nn_inc(nn_t out, nn_src_t in1) in nn_inc() argument
233 return nn_add_word(out, in1, WORD(1)); in nn_inc()
237 * Conditionally subtracts 'in2' from 'in1' according to "cnd",
239 * o out = in1 - in2 if cnd is not zero.
240 * o out = in1 if cnd is zero.
242 * 'in1' and 'in2' must point to initialized nn, such that the value of 'in1'
244 * same nn as 'in1' or 'in2'. If aliasing is not used, 'out' is initialized by
245 * the function. The length of 'out' is set to the length of 'in1'
250 int nn_cnd_sub(int cnd, nn_t out, nn_src_t in1, nn_src_t in2) in nn_cnd_sub() argument
257 ret = nn_check_initialized(in1); EG(ret, err); in nn_cnd_sub()
261 loop_wlen = LOCAL_MAX(in1->wlen, in2->wlen); in nn_cnd_sub()
262 if ((out != in1) && (out != in2)) { in nn_cnd_sub()
265 ret = nn_set_wlen(out, in1->wlen); EG(ret, err); in nn_cnd_sub()
270 tmp = (word_t)(in1->val[i] - (in2->val[i] & mask)); in nn_cnd_sub()
271 borrow1 = (word_t)(tmp > in1->val[i]); in nn_cnd_sub()
278 /* We only support the in1 >= in2 case */ in nn_cnd_sub()
286 int nn_sub(nn_t out, nn_src_t in1, nn_src_t in2) in nn_sub() argument
288 return nn_cnd_sub(1, out, in1, in2); in nn_sub()
292 * Compute out = in1 - 1 where in1 is a *positive* integer. Aliasing is
296 int nn_dec(nn_t out, nn_src_t in1) in nn_dec() argument
303 ret = nn_check_initialized(in1); EG(ret, err); in nn_dec()
304 n_wlen = in1->wlen; in nn_dec()
310 tmp = (word_t)(in1->val[i] - borrow); in nn_dec()
311 borrow = (word_t)(tmp > in1->val[i]); in nn_dec()
334 * Compute out = in1 + in2 mod p. The function returns 0 on success, -1 on
339 static int _nn_mod_add(nn_t out, nn_src_t in1, nn_src_t in2, nn_src_t p) in _nn_mod_add() argument
343 ret = nn_check_initialized(in1); EG(ret, err); in _nn_mod_add()
347 …SHOULD_HAVE((!nn_cmp(in1, p, &cmp)) && (cmp < 0), ret, err); /* a SHOULD_HAVE as documented above … in _nn_mod_add()
350 ret = nn_add(out, in1, in2); EG(ret, err); in _nn_mod_add()
360 * of in1 and in2 so getting a carry out does not necessarily mean in _nn_mod_add()
374 * Compute out = in1 + in2 mod p. The function returns 0 on success, -1 on
379 int nn_mod_add(nn_t out, nn_src_t in1, nn_src_t in2, nn_src_t p) in nn_mod_add() argument
388 ret = _nn_mod_add(out, in1, in2, &p_cpy); in nn_mod_add()
395 ret = _nn_mod_add(out, in1, in2, p); in nn_mod_add()
403 * Compute out = in1 + 1 mod p. The function returns 0 on success, -1 on error.
407 static int _nn_mod_inc(nn_t out, nn_src_t in1, nn_src_t p) in _nn_mod_inc() argument
411 ret = nn_check_initialized(in1); EG(ret, err); in _nn_mod_inc()
414 …SHOULD_HAVE((!nn_cmp(in1, p, &cmp)) && (cmp < 0), ret, err); /* a SHOULD_HAVE as documented above … in _nn_mod_inc()
416 ret = nn_inc(out, in1); EG(ret, err); in _nn_mod_inc()
428 * Compute out = in1 + 1 mod p. The function returns 0 on success, -1 on error.
432 int nn_mod_inc(nn_t out, nn_src_t in1, nn_src_t p) in nn_mod_inc() argument
441 ret = _nn_mod_inc(out, in1, &p_cpy); in nn_mod_inc()
448 ret = _nn_mod_inc(out, in1, p); in nn_mod_inc()
457 * Compute out = in1 - in2 mod p. The function returns 0 on success, -1 on
462 static int _nn_mod_sub(nn_t out, nn_src_t in1, nn_src_t in2, nn_src_t p) in _nn_mod_sub() argument
469 ret = nn_check_initialized(in1); EG(ret, err); in _nn_mod_sub()
473 …SHOULD_HAVE((!nn_cmp(in1, p, &cmp)) && (cmp < 0), ret, err); /* a SHOULD_HAVE as documented above … in _nn_mod_sub()
486 ret = nn_cmp(in1, in2_, &cmp); EG(ret, err); in _nn_mod_sub()
488 ret = nn_cnd_add(smaller, out, in1, p); EG(ret, err); in _nn_mod_sub()
500 * Compute out = in1 - in2 mod p. The function returns 0 on success, -1 on
505 int nn_mod_sub(nn_t out, nn_src_t in1, nn_src_t in2, nn_src_t p) in nn_mod_sub() argument
514 ret = _nn_mod_sub(out, in1, in2, &p_cpy); in nn_mod_sub()
521 ret = _nn_mod_sub(out, in1, in2, p); in nn_mod_sub()
529 * Compute out = in1 - 1 mod p. The function returns 0 on success, -1 on error
533 static int _nn_mod_dec(nn_t out, nn_src_t in1, nn_src_t p) in _nn_mod_dec() argument
537 ret = nn_check_initialized(in1); EG(ret, err); in _nn_mod_dec()
541 SHOULD_HAVE((!nn_cmp(in1, p, &cmp)) && (cmp < 0), ret, err); /* a SHOULD_HAVE; Documented above */ in _nn_mod_dec()
544 ret = nn_iszero(in1, &iszero); EG(ret, err); in _nn_mod_dec()
545 ret = nn_cnd_add(iszero, out, in1, p); EG(ret, err); in _nn_mod_dec()
555 * Compute out = in1 - 1 mod p. The function returns 0 on success, -1 on error
559 int nn_mod_dec(nn_t out, nn_src_t in1, nn_src_t p) in nn_mod_dec() argument
568 ret = _nn_mod_dec(out, in1, &p_cpy); in nn_mod_dec()
575 ret = _nn_mod_dec(out, in1, p); in nn_mod_dec()