Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------------------------------------------------------------------------------------
- // Big Number Representations
- //
- // Multiple precision numbers are arranged as an array of digits, with the least
- // significant digit coming first ("little-endian digit ordering"), regardless
- // of the word size or byte ordering of the digit itself.
- //
- // A single digit is either a DWORD (4 bytes) or a QWORD (8 bytes). A bignum that
- // consists of a series of DWORD digits is tagged "BnDw", whereas a bignum that
- // consists of a series of QWORD digits is tagged "BnQw". A bignum function
- // is tagged with one of these two to specify the digit size it expects, and it
- // takes a length parameter that specifies the number of digits in the number.
- //
- // Consider a 8-byte number written in radix 256 notation. Here R=256.
- //
- // b7*(R^7)+b6*(R^6)+b5*(R^5)+b4*(R^5)+b3*(R^3)+b2*(R^2)+b1*(R^1)+b0*(R^0)
- //
- // A BnDw bignum consists of a series of DWORD digits. The DWORD can be encoded
- // in either little-endian or big-endian byte ordering. Thus there are two
- // possible formats for these digits.
- //
- // DwLe [b0 b1 b2 b3][b4 b5 b6 b7]
- // DwBe [b3 b2 b1 b0][b7 b6 b5 b4]
- //
- // A BnQw bignum consists of a series of QWORD digits. The QWORD can be encoded
- // in either little-endian or big-endian byte ordering. Thus there are two
- // possible formats for these digits.
- //
- // QwLe [b0 b1 b2 b3 b4 b5 b6 b7]
- // QwBe [b7 b6 b5 b4 b3 b2 b1 b0]
- //
- // A particular platform has a natural byte order (Le or Be). We use the tag Ne
- // to mean the natural byte order.
- //
- // Most low level bignum routines require inputs that are in QwNe format. That
- // is, QWORD digits in natural byte order for the platform. They take an array
- // of QWORD digits and a count of digits. The caller is responsible for converting
- // the bignum into the expected format.
- //
- // A full complement of conversion functions is available. The BnDw functions
- // will convert a bignum made up of a series of DWORD digits between DwLe, DwBe,
- // and DwNe formats. The BnQw functions will convert a bignum made up of a series
- // of QWORD digits between QwLe, QwBe, and QwNe formats. The BnQw functions can
- // also convert between BnDw and BnQw bignum formats, but since the length parameter
- // specifies the number of QWORD digits, the BnDw bignum must contain an even number
- // of DWORD digits.
- //
- // When a bignum is to be stored or used on multiple platforms, the application
- // must choose a concrete representation for the number. In the case of digital
- // signatures, we choose to store them in QwBe format. This was chosen to match
- // the natural word size and byte ordering of the Xenon console, so that the
- // signature checking code would be as small and fast as possible on that platform.
- // ---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement