-
+ 2EA77D3E9C3D040649368883BDCAECA474685EF6968E358CDD744647292902E584E34949CABA771CB43145F3AC1FCE64932CF2E7D48AD514B84EE81FE5492C58
eucrypt/mpi/include/mpi-inline.h
(0 . 0)(1 . 121)
1227 /* mpi-inline.h - Internal to the Multi Precision Integers
1228 * Modified by No Such Labs. (C) 2015. See README.
1229 *
1230 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
1231 * SHA256(gnupg-1.4.10.tar.gz):
1232 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
1233 * (C) 1994-2005 Free Software Foundation, Inc.
1234 *
1235 * This program is free software: you can redistribute it and/or modify
1236 * it under the terms of the GNU General Public License as published by
1237 * the Free Software Foundation, either version 3 of the License, or
1238 * (at your option) any later version.
1239 *
1240 * This program is distributed in the hope that it will be useful,
1241 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1242 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1243 * GNU General Public License for more details.
1244 *
1245 * You should have received a copy of the GNU General Public License
1246 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1247 */
1248
1249 #ifndef G10_MPI_INLINE_H
1250 #define G10_MPI_INLINE_H
1251
1252 #ifndef G10_MPI_INLINE_DECL
1253 #define G10_MPI_INLINE_DECL extern __inline__
1254 #endif
1255
1256 G10_MPI_INLINE_DECL mpi_limb_t
1257 mpihelp_add_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
1258 mpi_size_t s1_size, mpi_limb_t s2_limb)
1259 {
1260 mpi_limb_t x;
1261
1262 x = *s1_ptr++;
1263 s2_limb += x;
1264 *res_ptr++ = s2_limb;
1265 if( s2_limb < x ) { /* sum is less than the left operand: handle carry */
1266 while( --s1_size ) {
1267 x = *s1_ptr++ + 1; /* add carry */
1268 *res_ptr++ = x; /* and store */
1269 if( x ) /* not 0 (no overflow): we can stop */
1270 goto leave;
1271 }
1272 return 1; /* return carry (size of s1 to small) */
1273 }
1274
1275 leave:
1276 if( res_ptr != s1_ptr ) { /* not the same variable */
1277 mpi_size_t i; /* copy the rest */
1278 for( i=0; i < s1_size-1; i++ )
1279 res_ptr[i] = s1_ptr[i];
1280 }
1281 return 0; /* no carry */
1282 }
1283
1284
1285
1286 G10_MPI_INLINE_DECL mpi_limb_t
1287 mpihelp_add(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
1288 mpi_ptr_t s2_ptr, mpi_size_t s2_size)
1289 {
1290 mpi_limb_t cy = 0;
1291
1292 if( s2_size )
1293 cy = mpihelp_add_n( res_ptr, s1_ptr, s2_ptr, s2_size );
1294
1295 if( s1_size - s2_size )
1296 cy = mpihelp_add_1( res_ptr + s2_size, s1_ptr + s2_size,
1297 s1_size - s2_size, cy);
1298 return cy;
1299 }
1300
1301
1302 G10_MPI_INLINE_DECL mpi_limb_t
1303 mpihelp_sub_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
1304 mpi_size_t s1_size, mpi_limb_t s2_limb )
1305 {
1306 mpi_limb_t x;
1307
1308 x = *s1_ptr++;
1309 s2_limb = x - s2_limb;
1310 *res_ptr++ = s2_limb;
1311 if( s2_limb > x ) {
1312 while( --s1_size ) {
1313 x = *s1_ptr++;
1314 *res_ptr++ = x - 1;
1315 if( x )
1316 goto leave;
1317 }
1318 return 1;
1319 }
1320
1321 leave:
1322 if( res_ptr != s1_ptr ) {
1323 mpi_size_t i;
1324 for( i=0; i < s1_size-1; i++ )
1325 res_ptr[i] = s1_ptr[i];
1326 }
1327 return 0;
1328 }
1329
1330
1331
1332 G10_MPI_INLINE_DECL mpi_limb_t
1333 mpihelp_sub( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
1334 mpi_ptr_t s2_ptr, mpi_size_t s2_size)
1335 {
1336 mpi_limb_t cy = 0;
1337
1338 if( s2_size )
1339 cy = mpihelp_sub_n(res_ptr, s1_ptr, s2_ptr, s2_size);
1340
1341 if( s1_size - s2_size )
1342 cy = mpihelp_sub_1(res_ptr + s2_size, s1_ptr + s2_size,
1343 s1_size - s2_size, cy);
1344 return cy;
1345 }
1346
1347 #endif /*G10_MPI_INLINE_H*/