File indexing completed on 2024-05-12 04:45:15
0001 /* 0002 Copyright (C) 1999-2007 The Botan Project. All rights reserved. 0003 0004 Redistribution and use in source and binary forms, for any use, with or without 0005 modification, is permitted provided that the following conditions are met: 0006 0007 1. Redistributions of source code must retain the above copyright notice, this 0008 list of conditions, and the following disclaimer. 0009 0010 2. Redistributions in binary form must reproduce the above copyright notice, 0011 this list of conditions, and the following disclaimer in the documentation 0012 and/or other materials provided with the distribution. 0013 0014 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED 0015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 0016 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. 0017 0018 IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, 0019 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 0020 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0021 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 0022 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 0023 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 0024 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0025 */ 0026 // LICENSEHEADER_END 0027 namespace QCA { // WRAPNS_LINE 0028 /************************************************* 0029 * MP Shift Algorithms Source File * 0030 * (C) 1999-2007 The Botan Project * 0031 *************************************************/ 0032 0033 } // WRAPNS_LINE 0034 #include <botan/mp_core.h> 0035 namespace QCA { // WRAPNS_LINE 0036 } // WRAPNS_LINE 0037 #include <botan/mem_ops.h> 0038 namespace QCA { // WRAPNS_LINE 0039 0040 namespace Botan { 0041 0042 extern "C" { 0043 0044 /************************************************* 0045 * Single Operand Left Shift * 0046 *************************************************/ 0047 void bigint_shl1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift) 0048 { 0049 if (word_shift) { 0050 for (u32bit j = 1; j != x_size + 1; ++j) 0051 x[(x_size - j) + word_shift] = x[x_size - j]; 0052 clear_mem(x, word_shift); 0053 } 0054 0055 if (bit_shift) { 0056 word carry = 0; 0057 for (u32bit j = word_shift; j != x_size + word_shift + 1; ++j) { 0058 word temp = x[j]; 0059 x[j] = (temp << bit_shift) | carry; 0060 carry = (temp >> (MP_WORD_BITS - bit_shift)); 0061 } 0062 } 0063 } 0064 0065 /************************************************* 0066 * Single Operand Right Shift * 0067 *************************************************/ 0068 void bigint_shr1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift) 0069 { 0070 if (x_size < word_shift) { 0071 clear_mem(x, x_size); 0072 return; 0073 } 0074 0075 if (word_shift) { 0076 for (u32bit j = 0; j != x_size - word_shift; ++j) 0077 x[j] = x[j + word_shift]; 0078 for (u32bit j = x_size - word_shift; j != x_size; ++j) 0079 x[j] = 0; 0080 } 0081 0082 if (bit_shift) { 0083 word carry = 0; 0084 for (u32bit j = x_size - word_shift; j > 0; --j) { 0085 word temp = x[j - 1]; 0086 x[j - 1] = (temp >> bit_shift) | carry; 0087 carry = (temp << (MP_WORD_BITS - bit_shift)); 0088 } 0089 } 0090 } 0091 0092 /************************************************* 0093 * Two Operand Left Shift * 0094 *************************************************/ 0095 void bigint_shl2(word y[], const word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift) 0096 { 0097 for (u32bit j = 0; j != x_size; ++j) 0098 y[j + word_shift] = x[j]; 0099 if (bit_shift) { 0100 word carry = 0; 0101 for (u32bit j = word_shift; j != x_size + word_shift + 1; ++j) { 0102 word temp = y[j]; 0103 y[j] = (temp << bit_shift) | carry; 0104 carry = (temp >> (MP_WORD_BITS - bit_shift)); 0105 } 0106 } 0107 } 0108 0109 /************************************************* 0110 * Two Operand Right Shift * 0111 *************************************************/ 0112 void bigint_shr2(word y[], const word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift) 0113 { 0114 if (x_size < word_shift) 0115 return; 0116 0117 for (u32bit j = 0; j != x_size - word_shift; ++j) 0118 y[j] = x[j + word_shift]; 0119 if (bit_shift) { 0120 word carry = 0; 0121 for (u32bit j = x_size - word_shift; j > 0; --j) { 0122 word temp = y[j - 1]; 0123 y[j - 1] = (temp >> bit_shift) | carry; 0124 carry = (temp << (MP_WORD_BITS - bit_shift)); 0125 } 0126 } 0127 } 0128 } 0129 0130 } 0131 } // WRAPNS_LINE