others/fw-verif/8051secureboot/fw/rsa.c
// decrypt msg, puts decrypted text in rsa_regs.opaddr
// returns length of decrypted message
decrypt msg, puts decrypted text in rsa_regs.opaddr
returns length of decrypted message
decrypt msg puts decrypted text in rsa_regs . opaddr returns length of decrypted message
int decrypt(unsigned char* msg){
    unsigned int i;
    if(msg != (unsigned char*)&rsa_regs.m)
    {
        unlock(RSA_M, (unsigned char*)&rsa_regs.m, (unsigned char*)&rsa_regs.m+N);
        writecarr(RSA_M, (unsigned char*)&rsa_regs.m, msg, N);
        lock(RSA_M, (unsigned char*)&rsa_regs.m, (unsigned char*)&rsa_regs.m + N);
    }
    unlock(prsao, rsa_regs.opaddr, rsa_regs.opaddr+N);
    unlock(RSA, &rsa_regs.start, (unsigned char*)(&rsa_regs.state+1));    
    writec(RSA, &rsa_regs.start, 1, 1);
    writec(RSA, &rsa_regs.state, 1, 1);
    while (readc(&rsa_regs.state) != 0);
    lock(prsao, rsa_regs.opaddr, rsa_regs.opaddr+N);
    lock(RSA, &rsa_regs.start, (unsigned char*)(&rsa_regs.state+1));    
    if(decrypted->padbyte != 1)
        return -1;
    removeOAEP();
    return unpad();
}
int decrypt ( unsigned char * msg ) { unsigned int i ; if ( msg != ( unsigned char * ) & rsa_regs . m ) { unlock ( RSA_M , ( unsigned char * ) & rsa_regs . m , ( unsigned char * ) & rsa_regs . m + N ) ; writecarr ( RSA_M , ( unsigned char * ) & rsa_regs . m , msg , N ) ; lock ( RSA_M , ( unsigned char * ) & rsa_regs . m , ( unsigned char * ) & rsa_regs . m + N ) ; } unlock ( prsao , rsa_regs . opaddr , rsa_regs . opaddr + N ) ; unlock ( RSA , & rsa_regs . start , ( unsigned char * ) ( & rsa_regs . state + 1 ) ) ; writec ( RSA , & rsa_regs . start , 1 , 1 ) ; writec ( RSA , & rsa_regs . state , 1 , 1 ) ; while ( readc ( & rsa_regs . state ) != 0 ) ; lock ( prsao , rsa_regs . opaddr , rsa_regs . opaddr + N ) ; lock ( RSA , & rsa_regs . start , ( unsigned char * ) ( & rsa_regs . state + 1 ) ) ; if ( decrypted -> padbyte != 1 ) return -1 ; removeOAEP ( ) ; return unpad ( ) ; }
decrypt msg, puts decrypted text in rsa_regs.opaddr
returns length of decrypted message
decrypt msg puts decrypted text in rsa_regs . opaddr returns length of decrypted message
//assume (rsa_ptr.state == 0); //if (nd()) sassert (rsa_ptr.state = 0); // copy msg into RSA m register //load(msg, N, (unsigned int)rsa_regs.m, 0); // lock message during exponentiation // decrypt //assume (rsa_regs.state == 0); //if (nd()) sassert (0); //if (nd()) sassert (0); //sassert (rsa_ptr.state == 1); //sassert (readc(&rsa_ptr.state) == 0); //c_exp();  // c abstraction //sassert (rsa_ptr.state != 1); //sassert (rsa_ptr.state == 0); //sassert (readc(&rsa_ptr.state) == 0); //char tmpState = rsa_regs.state; //if (nd()) sassert (0); //while(rsa_regs.state != 0); //sassert (rsa_ptr.state == 0); //sassert (readc(&rsa_ptr.state) == 0); //if (nd()) sassert (0); //sassert (tmpState == 0); // check pad byte