| BN_prodMod | Function (ROM Call 0x124)

rsa.h

void BN_prodMod (BN *dest, const BN *b, const BN *n);

Multiplies two big integers modulo n.

BN_prodMod calculates Y = (Y * B) mod N where Y, B and N are big integers (up to 2040 bits) stored in BN structures pointed to by dest, b and n respectively. This routine is used in TIOS for RSA encryption, but may be used for any other purposes too (see BN for more info about how RSA works).
Here is an example of program (called "Big Numbers") which takes three (arbitrarily large) integers A, B and N, calculates (A * B) mod N and returns the result (assuming that A, B and N are really integers, i.e. no checking is implemented). This program also illustrates how you can get "big" integers from the expression stack, and push them to it:

    // Perform big number arithmetic through BN_prodMod

    #define USE_TI89              // Compile for TI-89
    #define USE_TI92PLUS          // Compile for TI-92 Plus
    #define USE_V200              // Compile for V200

    #define OPTIMIZE_ROM_CALLS    // Use ROM Call Optimization
    #define MIN_AMS 101           // Compile for AMS 1.01 or higher
    #define SAVE_SCREEN           // Save/Restore LCD Contents
    #define RETURN_VALUE          // Return a Value

    #include <tigcclib.h>         // Include All Header Files

    #define GetBignumArg(ap, bn) \
      ({unsigned char __n = *--(unsigned char*)(ap); \
      char *__p = (char*)(bn) + __n; \
      (bn)->Len = __n; \
      while (__n--) *__p-- = *--(ap); \
      (void)*(ap)--; })

    void push_Bignum(BN *bn)
    {
      unsigned m, n = bn->Len;
      char *p = (char*)bn;
      m = n;
      while (n--) push_quantum (*++p);
      push_quantum_pair (m, POSINT_TAG);
    }

    void _main(void)
    {
      ESI argptr = top_estack;
      BN *a = malloc (256), *b = malloc (256), *c = malloc (256);
      GetBignumArg (argptr, a);
      GetBignumArg (argptr, b);
      GetBignumArg (argptr, c);
      while (GetArgType (top_estack) != END_TAG)  // Clean up arguments
        top_estack = next_expression_index (top_estack);
      top_estack--;
      BN_prodMod (a, b, c);
      push_Bignum (a);
      free (a); free (b); free (c);
    }

Used by: BN_power17Mod, BN_powerMod