qca
bit_ops.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1999-2007 The Botan Project. All rights reserved. 00003 00004 Redistribution and use in source and binary forms, for any use, with or without 00005 modification, is permitted provided that the following conditions are met: 00006 00007 1. Redistributions of source code must retain the above copyright notice, this 00008 list of conditions, and the following disclaimer. 00009 00010 2. Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions, and the following disclaimer in the documentation 00012 and/or other materials provided with the distribution. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED 00015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00016 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. 00017 00018 IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, 00019 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00020 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00021 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00022 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00023 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00024 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 */ 00026 // LICENSEHEADER_END 00027 namespace QCA { // WRAPNS_LINE 00028 /************************************************* 00029 * Bit/Word Operations Header File * 00030 * (C) 1999-2007 The Botan Project * 00031 *************************************************/ 00032 00033 #ifndef BOTAN_BIT_OPS_H__ 00034 #define BOTAN_BIT_OPS_H__ 00035 00036 } // WRAPNS_LINE 00037 #include <botan/types.h> 00038 namespace QCA { // WRAPNS_LINE 00039 00040 namespace Botan { 00041 00042 /************************************************* 00043 * Rotation Functions * 00044 *************************************************/ 00045 template<typename T> inline T rotate_left(T input, u32bit rot) 00046 { return (T)((input << rot) | (input >> (8*sizeof(T)-rot))); } 00047 00048 template<typename T> inline T rotate_right(T input, u32bit rot) 00049 { return (T)((input >> rot) | (input << (8*sizeof(T)-rot))); } 00050 00051 /************************************************* 00052 * Byte Extraction Function * 00053 *************************************************/ 00054 template<typename T> inline byte get_byte(u32bit byte_num, T input) 00055 { return (byte)(input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)); } 00056 00057 /************************************************* 00058 * Byte to Word Conversions * 00059 *************************************************/ 00060 inline u16bit make_u16bit(byte input0, byte input1) 00061 { return (u16bit)(((u16bit)input0 << 8) | input1); } 00062 00063 inline u32bit make_u32bit(byte input0, byte input1, byte input2, byte input3) 00064 { return (u32bit)(((u32bit)input0 << 24) | ((u32bit)input1 << 16) | 00065 ((u32bit)input2 << 8) | input3); } 00066 00067 inline u64bit make_u64bit(byte input0, byte input1, byte input2, byte input3, 00068 byte input4, byte input5, byte input6, byte input7) 00069 { 00070 return (u64bit)(((u64bit)input0 << 56) | ((u64bit)input1 << 48) | 00071 ((u64bit)input2 << 40) | ((u64bit)input3 << 32) | 00072 ((u64bit)input4 << 24) | ((u64bit)input5 << 16) | 00073 ((u64bit)input6 << 8) | input7); 00074 } 00075 00076 /************************************************* 00077 * XOR Functions * 00078 *************************************************/ 00079 void xor_buf(byte[], const byte[], u32bit); 00080 void xor_buf(byte[], const byte[], const byte[], u32bit); 00081 00082 /************************************************* 00083 * Misc Utility Functions * 00084 *************************************************/ 00085 bool power_of_2(u64bit); 00086 u32bit high_bit(u64bit); 00087 u32bit low_bit(u64bit); 00088 u32bit significant_bytes(u64bit); 00089 u32bit hamming_weight(u64bit); 00090 00091 } 00092 00093 #endif 00094 } // WRAPNS_LINE
KDE 4.4 API Reference