mpi-genesis 1
mpi_second_cut 2 * Modified by No Such Labs. (C) 2015. See README.
mpi-genesis 3 *
mpi_second_cut 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
mpi_second_cut 5 * SHA256(gnupg-1.4.10.tar.gz):
mpi_second_cut 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
mpi_second_cut 7 * (C) 1994-2005 Free Software Foundation, Inc.
mpi-genesis 8 *
mpi_second_cut 9 * This program is free software: you can redistribute it and/or modify
mpi-genesis 10 * it under the terms of the GNU General Public License as published by
mpi_second_cut 11 * the Free Software Foundation, either version 3 of the License, or
mpi-genesis 12 * (at your option) any later version.
mpi-genesis 13 *
mpi_second_cut 14 * This program is distributed in the hope that it will be useful,
mpi-genesis 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis 17 * GNU General Public License for more details.
mpi-genesis 18 *
mpi-genesis 19 * You should have received a copy of the GNU General Public License
mpi_second_cut 20 * along with this program. If not, see <http:
mpi-genesis 21 */
mpi-genesis 22
mpi-genesis 23 #ifndef G10_MPI_INLINE_H
mpi-genesis 24 #define G10_MPI_INLINE_H
mpi-genesis 25
mpi-genesis 26 #ifndef G10_MPI_INLINE_DECL
mpi-genesis 27 #define G10_MPI_INLINE_DECL extern __inline__
mpi-genesis 28 #endif
mpi-genesis 29
mpi-genesis 30 G10_MPI_INLINE_DECL mpi_limb_t
mpi-genesis 31 mpihelp_add_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
mpi-genesis 32 mpi_size_t s1_size, mpi_limb_t s2_limb)
mpi-genesis 33 {
mpi-genesis 34 mpi_limb_t x;
mpi-genesis 35
mpi-genesis 36 x = *s1_ptr++;
mpi-genesis 37 s2_limb += x;
mpi-genesis 38 *res_ptr++ = s2_limb;
mpi-genesis 39 if( s2_limb < x ) {
mpi-genesis 40 while( --s1_size ) {
mpi-genesis 41 x = *s1_ptr++ + 1;
mpi-genesis 42 *res_ptr++ = x;
mpi-genesis 43 if( x )
mpi-genesis 44 goto leave;
mpi-genesis 45 }
mpi-genesis 46 return 1;
mpi-genesis 47 }
mpi-genesis 48
mpi-genesis 49 leave:
mpi-genesis 50 if( res_ptr != s1_ptr ) {
mpi-genesis 51 mpi_size_t i;
mpi-genesis 52 for( i=0; i < s1_size-1; i++ )
mpi-genesis 53 res_ptr[i] = s1_ptr[i];
mpi-genesis 54 }
mpi-genesis 55 return 0;
mpi-genesis 56 }
mpi-genesis 57
mpi-genesis 58
mpi-genesis 59
mpi-genesis 60 G10_MPI_INLINE_DECL mpi_limb_t
mpi-genesis 61 mpihelp_add(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
mpi-genesis 62 mpi_ptr_t s2_ptr, mpi_size_t s2_size)
mpi-genesis 63 {
mpi-genesis 64 mpi_limb_t cy = 0;
mpi-genesis 65
mpi-genesis 66 if( s2_size )
mpi-genesis 67 cy = mpihelp_add_n( res_ptr, s1_ptr, s2_ptr, s2_size );
mpi-genesis 68
mpi-genesis 69 if( s1_size - s2_size )
mpi-genesis 70 cy = mpihelp_add_1( res_ptr + s2_size, s1_ptr + s2_size,
mpi-genesis 71 s1_size - s2_size, cy);
mpi-genesis 72 return cy;
mpi-genesis 73 }
mpi-genesis 74
mpi-genesis 75
mpi-genesis 76 G10_MPI_INLINE_DECL mpi_limb_t
mpi-genesis 77 mpihelp_sub_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
mpi-genesis 78 mpi_size_t s1_size, mpi_limb_t s2_limb )
mpi-genesis 79 {
mpi-genesis 80 mpi_limb_t x;
mpi-genesis 81
mpi-genesis 82 x = *s1_ptr++;
mpi-genesis 83 s2_limb = x - s2_limb;
mpi-genesis 84 *res_ptr++ = s2_limb;
mpi-genesis 85 if( s2_limb > x ) {
mpi-genesis 86 while( --s1_size ) {
mpi-genesis 87 x = *s1_ptr++;
mpi-genesis 88 *res_ptr++ = x - 1;
mpi-genesis 89 if( x )
mpi-genesis 90 goto leave;
mpi-genesis 91 }
mpi-genesis 92 return 1;
mpi-genesis 93 }
mpi-genesis 94
mpi-genesis 95 leave:
mpi-genesis 96 if( res_ptr != s1_ptr ) {
mpi-genesis 97 mpi_size_t i;
mpi-genesis 98 for( i=0; i < s1_size-1; i++ )
mpi-genesis 99 res_ptr[i] = s1_ptr[i];
mpi-genesis 100 }
mpi-genesis 101 return 0;
mpi-genesis 102 }
mpi-genesis 103
mpi-genesis 104
mpi-genesis 105
mpi-genesis 106 G10_MPI_INLINE_DECL mpi_limb_t
mpi-genesis 107 mpihelp_sub( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
mpi-genesis 108 mpi_ptr_t s2_ptr, mpi_size_t s2_size)
mpi-genesis 109 {
mpi-genesis 110 mpi_limb_t cy = 0;
mpi-genesis 111
mpi-genesis 112 if( s2_size )
mpi-genesis 113 cy = mpihelp_sub_n(res_ptr, s1_ptr, s2_ptr, s2_size);
mpi-genesis 114
mpi-genesis 115 if( s1_size - s2_size )
mpi-genesis 116 cy = mpihelp_sub_1(res_ptr + s2_size, s1_ptr + s2_size,
mpi-genesis 117 s1_size - s2_size, cy);
mpi-genesis 118 return cy;
mpi-genesis 119 }
mpi-genesis 120
mpi-genesis 121 #endif /*G10_MPI_INLINE_H*/