SSHSecure/dh/func_utils.go

53 lines
831 B
Go
Raw Normal View History

2021-05-23 04:49:08 -04:00
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
}