BigNum Math: Implementing Cryptographic Multiple Precision Arithmetic

Chapter 3: Basic Operations

3.1 Introduction

In the previous chapter, a series of low-level algorithms was established that dealt with initializing and maintaining mp_int structures. This chapter will discuss another set of seemingly non-algebraic algorithms that will form the low-level basis of the entire library. While these algorithms are relatively trivial, it is important to understand how they work before proceeding since these algorithms will be used almost intrinsically in the following chapters.

The algorithms in this chapter deal primarily with more "programmer" related tasks such as creating copies of mp_int structures, assigning small values to mp_int structures and comparisons of the values mp_int structures represent.

3.2 Assigning Values to mp_int Structures

3.2.1 Copying an mp_int

Assigning the value that a given mp_int structure represents to another mp_int structure shall be known as making a copy for the purposes of this text. The copy of the mp_int will be a separate entity that represents the same value as the mp_int it was copied from. The mp_copy algorithm provides this functionality (Figure 3.1).

Algorithm mp_copy.

Input. An mp_int a and b.

Output. Store a copy of a in b.

  1. If b.alloc < a.used then grow b to a.used digits. ( mp_grow)

  2. for n from 0 to a.used - 1 do

    • 2.1 b n ? a n

  3. for n from a.used to b.used - 1 do

    • 3.1 b n ? 0

  4. b.used ? a.used

  5. b.sign ? a.sign

  6. return( MP_OKAY

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Junction Field-Effect Transistors (JFET)
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.