MIRACL Reference Manual
CONTENTS 1
Contents
1 MIRACL Reference Manual 1
2 MIRACL Module Documentation 1
3 MIRACL Data Structure Documentation 72
1 MIRACL Reference Manual
Note: In these routines a big parameter can also be used wherever a flash is specified, but not vice-
versa. Further information may be gleaned from the (lightly) commented source code. An asterisk ∗ after
the name indicates that the function does not take a mip parameter if MR_GENERIC_MT is defined in
mirdef.h.
Low-level routines
Advanced arithmetic routines
Montgomery arithmetic routines
ZZn2 arithmetic routines
Elliptic curve routines
Encryption routines
Floating-slash routines
2 MIRACL Module Documentation
2.1 Low level routines
Functions
• void absol* (flash x, flash y)
• void add (big x, big y, big z)
• int big_to_bytes (int max, big x, char ∗ptr, BOOL justify)
• void bigbits (int n, big x)
• mr_small brand (void)
• void bytes_to_big (int len, char ∗ptr, big x)
• int cinnum (flash x, FILE ∗filep)
• int cinstr (flash x, char ∗string)
• int compare* (big x, big y)
• void convert (int n, big x)
• void copy* (flash x, flash y)
• int cotnum (flash x, FILE ∗filep)
• int cotstr (flash x, char ∗string)
• void decr (big x, int n, big z)
• void divide (big x, big y, big z)
• BOOL divisible (big x, big y)
• void ∗ ecp_memalloc (int num)
2.1 Low level routines 2
• void ecp_memkill (char ∗mem, int num)
• int exsign* (flash x)
• miracl ∗ get_mip ()
• int getdig (big x, int i)
• unsigned int igcd* (unsigned int x, unsigned int y)
• void incr (big x, int n, big z)
• BOOL init_big_from_rom (big x, int len, const mr_small ∗rom, int romsize, int ∗romptr)
• BOOL init_point_from_rom (epoint ∗P, int len, const mr_small ∗rom, int romsize, int ∗romptr)
• int innum (flash x, FILE ∗filep)
• void insign* (int s, flash x)
• int instr (flash x, char ∗string)
• void irand (mr_unsign32 seed)
• void lgconv (long n, big x)
• void mad (big x, big y, big z, big w, big q, big r)
• void ∗ memalloc (int num)
• void memkill (char ∗mem, int len)
• void mirexit (void)
• void mirkill* (big x)
• miracl ∗ mirsys (int nd, mr_small nb)
• flash mirvar (int iv)
• flash mirvar_mem (char ∗mem, int index)
• void multiply (big x, big y, big z)
• void negify* (flash x, flash y)
• mr_small normalise (big x, big y)
• int numdig (big x)
• int otnum (flash x, FILE ∗filep)
• int otstr (flash x, char ∗string)
• void premult (big x, int n, big z)
• void putdig (int n, big x, int i)
• int remain (big x, int n)
• void set_io_buffer_size (int len)
• void set_user_function (BOOL(∗user)(void))
• int size* (big x)
• int subdiv (big x, int n, big z)
• BOOL subdivisible (big x, int n)
• void subtract (big x, big y, big z)
• void zero* (flash x)
2.1.1 Function Documentation
2.1.1.1 void absol* (flash x, flash y)
Gives absolute value of a big or flash number
Parameters:
← x The number whose absolute value is to be computed
→ y = |x|
2.1 Low level routines 3
2.1.1.2 void add (big x, big y, big z)
Adds two big numbers
Parameters:
← x
← y
→ z = x + y
Example:
add(x, x, x); // This doubles the value of x
2.1.1.3 int big_to_bytes (int max, big x, char ∗ ptr, BOOL justify)
Converts a positive big number into a binary octet string. Error checking is carried out to ensure that the
function does not write beyond the limits of ptr if max > 0. If max = 0, no checking is carried out. If max
> 0 and justify = TRUE, the output is right-justified, otherwise leading zeros are suppressed
Parameters:
← max Maximum number of octets to be written in ptr
← x The original big number
→ ptr Destination of the binary octet string
← justify If TRUE, the output is right-justified, otherwise leading zeros are suppresed
Returns:
The number of bytes generated in ptr. If justify = TRUE then the return value is max
Precondition:
max must be greater than 0 if justify = TRUE
2.1.1.4 void bigbits (int n, big x)
Generates a big random number of given length. Uses the built-in simple random number generator ini-
tialised by irand()
Parameters:
← n The desired length of the random big number
→ x The random number
2.1.1.5 mr_small brand (void)
Generates random integer number
Returns:
A random integer number
2.1 Low level routines 4
Precondition:
First use must be preceded by an initial call to irand()
Warning:
This generator is not cryptographically strong. For cryptographic applications, use the strong_rng()
routine
2.1.1.6 void bytes_to_big (int len, char ∗ ptr, big x)
Converts a binary octet string to a big number. Binary to big conversion
Parameters:
← len Length of ptr
← ptr Byte array of the binary octet string
→ x Big result
Example:
#include <stdio.h>
#include "miracl.h"
int main()
{
int i, len;
miracl
*
mip = mirsys(100, 0);
big x, y;
char b[200]; // b needs space allocated to it
x = mirvar(0); // all big variables need to be "mirvar"ed
y = mirvar(0);
expb2(100, x);
incr(x, 3, x); // x = 2^100 + 3
len = big_to_bytes(200, x, b, FALSE);
// Now b contains big number x in raw binary
// It is len bytes in length
// now print out the raw binary number b in hex
for (i = 0; i < len; i++) printf("%02x", b[i]);
printf("\n");
// now convert it back to big format, and print it out again
bytes_to_big(len, b, y);
mip->IOBASE = 16;
cotnum(y, stdout);
return 0;
}
2.1.1.7 int cinnum (flash x, FILE ∗ filep)
Inputs a flash/big number from the keyboard or a file, using as number base the current value of the instance
variable
miracl::IOBASE. Flash numbers can be entered using either a slash ‘/’ to indicate numerator and
denominator, or with a radix point
Parameters:
→ x Big/flash number
- 1
- 2
前往页