1 /* ********************************************************************* 2 * 3 * Sun elects to have this file available under and governed by the 4 * Mozilla Public License Version 1.1 ("MPL") (see 5 * http://www.mozilla.org/MPL/ for full license text). For the avoidance 6 * of doubt and subject to the following, Sun also elects to allow 7 * licensees to use this file under the MPL, the GNU General Public 8 * License version 2 only or the Lesser General Public License version 9 * 2.1 only. Any references to the "GNU General Public License version 2 10 * or later" or "GPL" in the following shall be construed to mean the 11 * GNU General Public License version 2 only. Any references to the "GNU 12 * Lesser General Public License version 2.1 or later" or "LGPL" in the 13 * following shall be construed to mean the GNU Lesser General Public 14 * License version 2.1 only. However, the following notice accompanied 15 * the original version of this file: 16 * 17 * 18 * Bitwise logical operations on MPI values 19 * 20 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 21 * 22 * The contents of this file are subject to the Mozilla Public License Version 23 * 1.1 (the "License"); you may not use this file except in compliance with 24 * the License. You may obtain a copy of the License at 25 * http://www.mozilla.org/MPL/ 26 * 27 * Software distributed under the License is distributed on an "AS IS" basis, 28 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 29 * for the specific language governing rights and limitations under the 30 * License. 31 * 32 * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. 33 * 34 * The Initial Developer of the Original Code is 35 * Michael J. Fromberger. 36 * Portions created by the Initial Developer are Copyright (C) 1998 37 * the Initial Developer. All Rights Reserved. 38 * 39 * Contributor(s): 40 * 41 * Alternatively, the contents of this file may be used under the terms of 42 * either the GNU General Public License Version 2 or later (the "GPL"), or 43 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 44 * in which case the provisions of the GPL or the LGPL are applicable instead 45 * of those above. If you wish to allow use of your version of this file only 46 * under the terms of either the GPL or the LGPL, and not to allow others to 47 * use your version of this file under the terms of the MPL, indicate your 48 * decision by deleting the provisions above and replace them with the notice 49 * and other provisions required by the GPL or the LGPL. If you do not delete 50 * the provisions above, a recipient may use your version of this file under 51 * the terms of any one of the MPL, the GPL or the LGPL. 52 * 53 *********************************************************************** */ 54 /* 55 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 56 * Use is subject to license terms. 57 */ 58 59 #ifndef _MPLOGIC_H 60 #define _MPLOGIC_H 61 62 /* $Id: mplogic.h,v 1.7 2004/04/27 23:04:36 gerv%gerv.net Exp $ */ 63 64 #include "mpi.h" 65 66 /* 67 The logical operations treat an mp_int as if it were a bit vector, 68 without regard to its sign (an mp_int is represented in a signed 69 magnitude format). Values are treated as if they had an infinite 70 string of zeros left of the most-significant bit. 71 */ 72 73 /* Parity results */ 74 75 #define MP_EVEN MP_YES 76 #define MP_ODD MP_NO 77 78 /* Bitwise functions */ 79 80 mp_err mpl_not(mp_int *a, mp_int *b); /* one's complement */ 81 mp_err mpl_and(mp_int *a, mp_int *b, mp_int *c); /* bitwise AND */ 82 mp_err mpl_or(mp_int *a, mp_int *b, mp_int *c); /* bitwise OR */ 83 mp_err mpl_xor(mp_int *a, mp_int *b, mp_int *c); /* bitwise XOR */ 84 85 /* Shift functions */ 86 87 mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d); /* right shift */ 88 mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d); /* left shift */ 89 90 /* Bit count and parity */ 91 92 mp_err mpl_num_set(mp_int *a, int *num); /* count set bits */ 93 mp_err mpl_num_clear(mp_int *a, int *num); /* count clear bits */ 94 mp_err mpl_parity(mp_int *a); /* determine parity */ 95 96 /* Get & Set the value of a bit */ 97 98 mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value); 99 mp_err mpl_get_bit(const mp_int *a, mp_size bitNum); 100 mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits); 101 mp_err mpl_significant_bits(const mp_int *a); 102 103 #endif /* _MPLOGIC_H */