diff --git a/dh/.gitignore b/dh/.gitignore new file mode 100644 index 0000000..aac1ca7 --- /dev/null +++ b/dh/.gitignore @@ -0,0 +1 @@ +moduli.c diff --git a/dh/const.go b/dh/const.go index c96e396..6934771 100644 --- a/dh/const.go +++ b/dh/const.go @@ -30,11 +30,3 @@ const ( var ( ) - -// Bit* functions operate on 32-bit words -func BitClear(a []uint32, n uint32) (i uint32) { - - i = a[n >> ShiftWord] &= ~(uint32(1) << (n & 31)) - - return -} diff --git a/dh/func_utils.go b/dh/func_utils.go new file mode 100644 index 0000000..c88f509 --- /dev/null +++ b/dh/func_utils.go @@ -0,0 +1,52 @@ +package dh + +func bitShiftWord(a []uint32, n uint32) (i uint32) { + + i = a[n>>ShiftWord] + + return +} + +// Bit* functions operate on 32-bit words +func BitClear(a []uint32, n uint32) (i uint32) { + + /* + #define BIT_CLEAR(a,n) ((a)[(n)>>SHIFT_WORD] &= ~(1L << ((n) & 31))) + */ + + var x uint32 = bitShiftWord(a, n) + var y uint32 = uint32(1) << (n & 31) + var z uint32 = ^y + + i = x & z + + return +} + +func BitSet(a []uint32, n uint32) (i uint32) { + + /* + #define BIT_SET(a,n) ((a)[(n)>>SHIFT_WORD] |= (1L << ((n) & 31))) + */ + + var x uint32 = bitShiftWord(a, n) + var y uint32 = uint32(1) << (n & 31) + + i = x | y + + return +} + +func BitTest(a []uint32, n uint32) (i uint32) { + + /* + #define BIT_TEST(a,n) ((a)[(n)>>SHIFT_WORD] & (1L << ((n) & 31))) + */ + + var x uint32 = bitShiftWord(a, n) + var y uint32 = uint32(1) << (n & 31) + + i = x & y + + return +}