#ifndef BLK256_H #define BLK256_H 1 #include #include "blk128.h" BEGIN_C_DECLS /** * Useful macros */ #define blk256_set(t, max, x3, x2, x1, x0) \ do { \ char tmx = max; \ uint64_t tx3 = x3; \ uint64_t tx2 = x2; \ uint64_t tx1 = x1; \ uint64_t tx0 = x0; \ (t)->mx = tmx; \ (t)->x[3] = tx3; \ (t)->x[2] = tx2; \ (t)->x[1] = tx1; \ (t)->x[0] = tx0; \ } while(0) #define blk256_zero(t) blk256_set(t, 0, 0, 0, 0, 0) #define blk256_cp(t, s) blk256_set(t, (s)->mx, (s)->x[3], (s)->x[2], (s)->x[1], (s)->x[0]) /* * Compare op1 and op2 and return -1 if op1 is smaller than op2, 0 if they are * equal or 1 if op2 is smaller than op1. */ int blk256_cmp(blk256_t *op1, blk256_t *op2); /** * Add op1 to op2 assuming the result will fit within 257 bits */ void blk256_add(blk256_t *rop, blk256_t *op1, blk256_t *op2); /** * Add a 128-bit number to 'op' putting the result in 'rop'. The output operand * may be the same as the input operand (the minuend). * * It is assumed that the op + inc can be represented in 257 bits */ void blk256_add_blk128(blk256_t *rop, blk256_t *op, blk128_t *inc); /** * Subtraction: Subtract op2 from op1 under the assumption that the subtraction * will yield a positive number (otherwise it is not valid) */ void blk256_sub(blk256_t *rop, blk256_t *op1, blk256_t *op2); /** * Subtract a 128-bit number from a 256-bit block. It is assumed op >= inc */ void blk256_sub_blk128(blk256_t *rop, blk256_t *op, blk128_t *dec); /** * Subtract 64-bit number from op, putting the result in rop */ void blk256_sub_u64(blk256_t *rop, blk256_t *op, uint64_t x); /** * Multiply a 256-bit number by a 128-bit number * * There are some rules that must be observed for this calculation to make * sense. * * - x.mx and x.x3 must be zero! */ void blk256_mul_blk128(blk256_t *rop, blk256_t *x, blk128_t *y); /** * Divide 256-bit number by 128-bit number */ void blk256_div_blk128(blk256_t *q, blk128_t *r, blk256_t *x, blk128_t *d); /** * Compare two mismatched numbers */ int blk256_cmp_blk128(blk256_t *op1, blk128_t *op2); /** * Increment a 256-bit number */ void blk256_inc(blk256_t *op); /** * Decrement a 256-bit number */ void blk256_dec(blk256_t *op); /** * Represent a 256-bit number as a double */ double blk256_as_double(blk256_t *op); /** * double to 256-bit number */ void double_as_blk256(blk256_t *rop, double x); END_C_DECLS #endif /* BLK256_H */