Back to index

lightning-sunbird  0.9+nobinonly
mplogic.h
Go to the documentation of this file.
00001 /*
00002  *  mplogic.h
00003  *
00004  *  Bitwise logical operations on MPI values
00005  *
00006  * ***** BEGIN LICENSE BLOCK *****
00007  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00008  *
00009  * The contents of this file are subject to the Mozilla Public License Version
00010  * 1.1 (the "License"); you may not use this file except in compliance with
00011  * the License. You may obtain a copy of the License at
00012  * http://www.mozilla.org/MPL/
00013  *
00014  * Software distributed under the License is distributed on an "AS IS" basis,
00015  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  * for the specific language governing rights and limitations under the
00017  * License.
00018  *
00019  * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
00020  *
00021  * The Initial Developer of the Original Code is
00022  * Michael J. Fromberger.
00023  * Portions created by the Initial Developer are Copyright (C) 1998
00024  * the Initial Developer. All Rights Reserved.
00025  *
00026  * Contributor(s):
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 /* $Id: mplogic.h,v 1.7 2004/04/27 23:04:36 gerv%gerv.net Exp $ */
00042 
00043 #ifndef _H_MPLOGIC_
00044 #define _H_MPLOGIC_
00045 
00046 #include "mpi.h"
00047 
00048 /*
00049   The logical operations treat an mp_int as if it were a bit vector,
00050   without regard to its sign (an mp_int is represented in a signed
00051   magnitude format).  Values are treated as if they had an infinite
00052   string of zeros left of the most-significant bit.
00053  */
00054 
00055 /* Parity results                    */
00056 
00057 #define MP_EVEN       MP_YES
00058 #define MP_ODD        MP_NO
00059 
00060 /* Bitwise functions                 */
00061 
00062 mp_err mpl_not(mp_int *a, mp_int *b);            /* one's complement  */
00063 mp_err mpl_and(mp_int *a, mp_int *b, mp_int *c); /* bitwise AND       */
00064 mp_err mpl_or(mp_int *a, mp_int *b, mp_int *c);  /* bitwise OR        */
00065 mp_err mpl_xor(mp_int *a, mp_int *b, mp_int *c); /* bitwise XOR       */
00066 
00067 /* Shift functions                   */
00068 
00069 mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d);   /* right shift    */
00070 mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d);   /* left shift     */
00071 
00072 /* Bit count and parity              */
00073 
00074 mp_err mpl_num_set(mp_int *a, int *num);         /* count set bits    */
00075 mp_err mpl_num_clear(mp_int *a, int *num);       /* count clear bits  */
00076 mp_err mpl_parity(mp_int *a);                    /* determine parity  */
00077 
00078 /* Get & Set the value of a bit */
00079 
00080 mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value);
00081 mp_err mpl_get_bit(const mp_int *a, mp_size bitNum);
00082 mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits);
00083 mp_err mpl_significant_bits(const mp_int *a);
00084 
00085 #endif /* end _H_MPLOGIC_ */