Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * mplogic.h |
michael@0 | 3 | * |
michael@0 | 4 | * Bitwise logical operations on MPI values |
michael@0 | 5 | * |
michael@0 | 6 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 9 | |
michael@0 | 10 | #ifndef _H_MPLOGIC_ |
michael@0 | 11 | #define _H_MPLOGIC_ |
michael@0 | 12 | |
michael@0 | 13 | #include "mpi.h" |
michael@0 | 14 | |
michael@0 | 15 | /* |
michael@0 | 16 | The logical operations treat an mp_int as if it were a bit vector, |
michael@0 | 17 | without regard to its sign (an mp_int is represented in a signed |
michael@0 | 18 | magnitude format). Values are treated as if they had an infinite |
michael@0 | 19 | string of zeros left of the most-significant bit. |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | /* Parity results */ |
michael@0 | 23 | |
michael@0 | 24 | #define MP_EVEN MP_YES |
michael@0 | 25 | #define MP_ODD MP_NO |
michael@0 | 26 | |
michael@0 | 27 | /* Bitwise functions */ |
michael@0 | 28 | |
michael@0 | 29 | mp_err mpl_not(mp_int *a, mp_int *b); /* one's complement */ |
michael@0 | 30 | mp_err mpl_and(mp_int *a, mp_int *b, mp_int *c); /* bitwise AND */ |
michael@0 | 31 | mp_err mpl_or(mp_int *a, mp_int *b, mp_int *c); /* bitwise OR */ |
michael@0 | 32 | mp_err mpl_xor(mp_int *a, mp_int *b, mp_int *c); /* bitwise XOR */ |
michael@0 | 33 | |
michael@0 | 34 | /* Shift functions */ |
michael@0 | 35 | |
michael@0 | 36 | mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d); /* right shift */ |
michael@0 | 37 | mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d); /* left shift */ |
michael@0 | 38 | |
michael@0 | 39 | /* Bit count and parity */ |
michael@0 | 40 | |
michael@0 | 41 | mp_err mpl_num_set(mp_int *a, int *num); /* count set bits */ |
michael@0 | 42 | mp_err mpl_num_clear(mp_int *a, int *num); /* count clear bits */ |
michael@0 | 43 | mp_err mpl_parity(mp_int *a); /* determine parity */ |
michael@0 | 44 | |
michael@0 | 45 | /* Get & Set the value of a bit */ |
michael@0 | 46 | |
michael@0 | 47 | mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value); |
michael@0 | 48 | mp_err mpl_get_bit(const mp_int *a, mp_size bitNum); |
michael@0 | 49 | mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits); |
michael@0 | 50 | mp_err mpl_significant_bits(const mp_int *a); |
michael@0 | 51 | |
michael@0 | 52 | #endif /* end _H_MPLOGIC_ */ |