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