|
@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
26
|
26
|
#include <stdint.h>
|
27
|
27
|
#include <string.h>
|
28
|
28
|
#include <assert.h>
|
|
29
|
+#include <ipxe/profile.h>
|
29
|
30
|
#include <ipxe/bigint.h>
|
30
|
31
|
|
31
|
32
|
/** @file
|
|
@@ -33,6 +34,22 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
33
|
34
|
* Big integer support
|
34
|
35
|
*/
|
35
|
36
|
|
|
37
|
+/** Modular multiplication overall profiler */
|
|
38
|
+static struct profiler bigint_mod_multiply_profiler __profiler =
|
|
39
|
+ { .name = "bigint_mod_multiply" };
|
|
40
|
+
|
|
41
|
+/** Modular multiplication multiply step profiler */
|
|
42
|
+static struct profiler bigint_mod_multiply_multiply_profiler __profiler =
|
|
43
|
+ { .name = "bigint_mod_multiply.multiply" };
|
|
44
|
+
|
|
45
|
+/** Modular multiplication rescale step profiler */
|
|
46
|
+static struct profiler bigint_mod_multiply_rescale_profiler __profiler =
|
|
47
|
+ { .name = "bigint_mod_multiply.rescale" };
|
|
48
|
+
|
|
49
|
+/** Modular multiplication subtract step profiler */
|
|
50
|
+static struct profiler bigint_mod_multiply_subtract_profiler __profiler =
|
|
51
|
+ { .name = "bigint_mod_multiply.subtract" };
|
|
52
|
+
|
36
|
53
|
/**
|
37
|
54
|
* Perform modular multiplication of big integers
|
38
|
55
|
*
|
|
@@ -63,31 +80,43 @@ void bigint_mod_multiply_raw ( const bigint_element_t *multiplicand0,
|
63
|
80
|
int rotation;
|
64
|
81
|
int i;
|
65
|
82
|
|
|
83
|
+ /* Start profiling */
|
|
84
|
+ profile_start ( &bigint_mod_multiply_profiler );
|
|
85
|
+
|
66
|
86
|
/* Sanity check */
|
67
|
87
|
assert ( sizeof ( *temp ) == bigint_mod_multiply_tmp_len ( modulus ) );
|
68
|
88
|
|
69
|
89
|
/* Perform multiplication */
|
|
90
|
+ profile_start ( &bigint_mod_multiply_multiply_profiler );
|
70
|
91
|
bigint_multiply ( multiplicand, multiplier, &temp->result );
|
|
92
|
+ profile_stop ( &bigint_mod_multiply_multiply_profiler );
|
71
|
93
|
|
72
|
94
|
/* Rescale modulus to match result */
|
|
95
|
+ profile_start ( &bigint_mod_multiply_rescale_profiler );
|
73
|
96
|
bigint_grow ( modulus, &temp->modulus );
|
74
|
97
|
rotation = ( bigint_max_set_bit ( &temp->result ) -
|
75
|
98
|
bigint_max_set_bit ( &temp->modulus ) );
|
76
|
99
|
for ( i = 0 ; i < rotation ; i++ )
|
77
|
100
|
bigint_rol ( &temp->modulus );
|
|
101
|
+ profile_stop ( &bigint_mod_multiply_rescale_profiler );
|
78
|
102
|
|
79
|
103
|
/* Subtract multiples of modulus */
|
|
104
|
+ profile_start ( &bigint_mod_multiply_subtract_profiler );
|
80
|
105
|
for ( i = 0 ; i <= rotation ; i++ ) {
|
81
|
106
|
if ( bigint_is_geq ( &temp->result, &temp->modulus ) )
|
82
|
107
|
bigint_subtract ( &temp->modulus, &temp->result );
|
83
|
108
|
bigint_ror ( &temp->modulus );
|
84
|
109
|
}
|
|
110
|
+ profile_stop ( &bigint_mod_multiply_subtract_profiler );
|
85
|
111
|
|
86
|
112
|
/* Resize result */
|
87
|
113
|
bigint_shrink ( &temp->result, result );
|
88
|
114
|
|
89
|
115
|
/* Sanity check */
|
90
|
116
|
assert ( bigint_is_geq ( modulus, result ) );
|
|
117
|
+
|
|
118
|
+ /* Stop profiling */
|
|
119
|
+ profile_stop ( &bigint_mod_multiply_profiler );
|
91
|
120
|
}
|
92
|
121
|
|
93
|
122
|
/**
|