iPXE
Functions
x86_bigint.c File Reference

Big integer support. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/bigint.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void bigint_multiply_raw (const uint32_t *multiplicand0, unsigned int multiplicand_size, const uint32_t *multiplier0, unsigned int multiplier_size, uint32_t *result0)
 Multiply big integers. More...
 

Detailed Description

Big integer support.

Definition in file x86_bigint.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ bigint_multiply_raw()

void bigint_multiply_raw ( const uint32_t multiplicand0,
unsigned int  multiplicand_size,
const uint32_t multiplier0,
unsigned int  multiplier_size,
uint32_t result0 
)

Multiply big integers.

Parameters
multiplicand0Element 0 of big integer to be multiplied
multiplicand_sizeNumber of elements in multiplicand
multiplier0Element 0 of big integer to be multiplied
multiplier_sizeNumber of elements in multiplier
result0Element 0 of big integer to hold result

Definition at line 44 of file x86_bigint.c.

48  {
49  unsigned int result_size = ( multiplicand_size + multiplier_size );
50  const bigint_t ( multiplicand_size ) __attribute__ (( may_alias ))
51  *multiplicand = ( ( const void * ) multiplicand0 );
52  const bigint_t ( multiplier_size ) __attribute__ (( may_alias ))
53  *multiplier = ( ( const void * ) multiplier0 );
54  bigint_t ( result_size ) __attribute__ (( may_alias ))
55  *result = ( ( void * ) result0 );
56  unsigned int i;
57  unsigned int j;
58  uint32_t multiplicand_element;
59  uint32_t multiplier_element;
60  uint32_t *result_elements;
61  uint32_t discard_a;
62  uint32_t discard_d;
63  long index;
64 
65  /* Zero result */
66  memset ( result, 0, sizeof ( *result ) );
67 
68  /* Multiply integers one element at a time */
69  for ( i = 0 ; i < multiplicand_size ; i++ ) {
70  multiplicand_element = multiplicand->element[i];
71  for ( j = 0 ; j < multiplier_size ; j++ ) {
72  multiplier_element = multiplier->element[j];
73  result_elements = &result->element[ i + j ];
74  /* Perform a single multiply, and add the
75  * resulting double-element into the result,
76  * carrying as necessary. The carry can
77  * never overflow beyond the end of the
78  * result, since:
79  *
80  * a < 2^{n}, b < 2^{m} => ab < 2^{n+m}
81  */
82  __asm__ __volatile__ ( "mull %5\n\t"
83  "addl %%eax, (%6,%2,4)\n\t"
84  "adcl %%edx, 4(%6,%2,4)\n\t"
85  "\n1:\n\t"
86  "adcl $0, 8(%6,%2,4)\n\t"
87  "inc %2\n\t"
88  /* Does not affect CF */
89  "jc 1b\n\t"
90  : "=&a" ( discard_a ),
91  "=&d" ( discard_d ),
92  "=&r" ( index ),
93  "+m" ( *result )
94  : "0" ( multiplicand_element ),
95  "g" ( multiplier_element ),
96  "r" ( result_elements ),
97  "2" ( 0 ) );
98  }
99  }
100 }
#define __attribute__(x)
Definition: compiler.h:10
static const void const void void * result
Definition: crypto.h:335
uint8_t multiplier
Port multiplier number.
Definition: edd.h:32
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
unsigned int uint32_t
Definition: stdint.h:12
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
typedef bigint_t(X25519_SIZE) x25519_t
An X25519 unsigned big integer used in internal calculations.
void * memset(void *dest, int character, size_t len) __nonnull

References __asm__(), __attribute__, __volatile__(), bigint_t(), index, memset(), multiplier, and result.