monotone

monotone Mtn Source Tree

Root/botan/mp_smul.cpp

1/*************************************************
2* Simple Multiplication Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/mp_core.h>
7#include <botan/mp_madd.h>
8#include <botan/mem_ops.h>
9
10namespace Botan {
11
12/*************************************************
13* Two Operand Linear Multiply *
14*************************************************/
15void bigint_linmul2(word x[], u32bit x_size, word y)
16 {
17 word carry = 0;
18 for(u32bit j = 0; j != x_size; j++)
19 bigint_madd(x[j], y, carry, 0, x + j, &carry);
20 x[x_size] = carry;
21 }
22
23/*************************************************
24* Three Operand Linear Multiply *
25*************************************************/
26void bigint_linmul3(word z[], const word x[], u32bit x_size, word y)
27 {
28 word carry = 0;
29 for(u32bit j = 0; j != x_size; j++)
30 bigint_madd(x[j], y, carry, 0, z + j, &carry);
31 z[x_size] = carry;
32 }
33
34/*************************************************
35* Simple O(N^2) Multiplication *
36*************************************************/
37void bigint_smul(word z[], const word x[], u32bit x_size,
38 const word y[], u32bit y_size)
39 {
40 const u32bit blocks = y_size - (y_size % 8);
41
42 clear_mem(z, x_size + y_size);
43
44 for(u32bit j = 0; j != x_size; j++)
45 {
46 const word x_j = x[j];
47
48 word carry = 0;
49
50 for(u32bit k = 0; k != blocks; k += 8)
51 {
52 bigint_madd(x_j, y[k+0], z[j+k+0], carry, z + (j+k+0), &carry);
53 bigint_madd(x_j, y[k+1], z[j+k+1], carry, z + (j+k+1), &carry);
54 bigint_madd(x_j, y[k+2], z[j+k+2], carry, z + (j+k+2), &carry);
55 bigint_madd(x_j, y[k+3], z[j+k+3], carry, z + (j+k+3), &carry);
56 bigint_madd(x_j, y[k+4], z[j+k+4], carry, z + (j+k+4), &carry);
57 bigint_madd(x_j, y[k+5], z[j+k+5], carry, z + (j+k+5), &carry);
58 bigint_madd(x_j, y[k+6], z[j+k+6], carry, z + (j+k+6), &carry);
59 bigint_madd(x_j, y[k+7], z[j+k+7], carry, z + (j+k+7), &carry);
60 }
61
62 for(u32bit k = blocks; k != y_size; k++)
63 bigint_madd(x_j, y[k], z[j+k], carry, z + (j+k), &carry);
64 z[j+y_size] = carry;
65 }
66 }
67
68}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status