michael@0: /* michael@0: * mplogic.h michael@0: * michael@0: * Bitwise logical operations on MPI values michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _H_MPLOGIC_ michael@0: #define _H_MPLOGIC_ michael@0: michael@0: #include "mpi.h" michael@0: michael@0: /* michael@0: The logical operations treat an mp_int as if it were a bit vector, michael@0: without regard to its sign (an mp_int is represented in a signed michael@0: magnitude format). Values are treated as if they had an infinite michael@0: string of zeros left of the most-significant bit. michael@0: */ michael@0: michael@0: /* Parity results */ michael@0: michael@0: #define MP_EVEN MP_YES michael@0: #define MP_ODD MP_NO michael@0: michael@0: /* Bitwise functions */ michael@0: michael@0: mp_err mpl_not(mp_int *a, mp_int *b); /* one's complement */ michael@0: mp_err mpl_and(mp_int *a, mp_int *b, mp_int *c); /* bitwise AND */ michael@0: mp_err mpl_or(mp_int *a, mp_int *b, mp_int *c); /* bitwise OR */ michael@0: mp_err mpl_xor(mp_int *a, mp_int *b, mp_int *c); /* bitwise XOR */ michael@0: michael@0: /* Shift functions */ michael@0: michael@0: mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d); /* right shift */ michael@0: mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d); /* left shift */ michael@0: michael@0: /* Bit count and parity */ michael@0: michael@0: mp_err mpl_num_set(mp_int *a, int *num); /* count set bits */ michael@0: mp_err mpl_num_clear(mp_int *a, int *num); /* count clear bits */ michael@0: mp_err mpl_parity(mp_int *a); /* determine parity */ michael@0: michael@0: /* Get & Set the value of a bit */ michael@0: michael@0: mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value); michael@0: mp_err mpl_get_bit(const mp_int *a, mp_size bitNum); michael@0: mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits); michael@0: mp_err mpl_significant_bits(const mp_int *a); michael@0: michael@0: #endif /* end _H_MPLOGIC_ */