Esempio n. 1
0
static int  AesAlign16(Aes* aes, byte* out, const byte* in, word32 sz, word32 dir, word32 mode)
{
    wolfSSL_TI_lockCCM() ;
    ROM_AESReset(AES_BASE);
    ROM_AESConfigSet(AES_BASE, (aes->keylen | dir |
                                (mode==AES_CFG_MODE_CTR_NOCTR ? AES_CFG_MODE_CTR : mode)));
    ROM_AESIVSet(AES_BASE, aes->reg);
    ROM_AESKey1Set(AES_BASE, aes->key, aes->keylen);
    if((dir == AES_CFG_DIR_DECRYPT)&& (mode == AES_CFG_MODE_CBC))
        /* if input and output same will overwrite input iv */
        XMEMCPY(aes->tmp, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
    ROM_AESDataProcess(AES_BASE, (uint32_t *)in, (uint32_t *)out, sz);
    wolfSSL_TI_unlockCCM() ;

    /* store iv for next call */
    if(mode == AES_CFG_MODE_CBC) {
        if(dir == AES_CFG_DIR_ENCRYPT)
            XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
        else
            XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
    }

    if(mode == AES_CFG_MODE_CTR) {
        do {
            int i ;
            for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) {
                if (++((byte *)aes->reg)[i])
                    break ;
            }
            sz -= AES_BLOCK_SIZE ;
        } while((int)sz > 0) ;
    }

    return 0 ;
}
Esempio n. 2
0
static int hashGetHash(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hsize)
{   
    uint32_t h[16] ;
#ifndef TI_DUMMY_BUILD
    wolfSSL_TI_lockCCM() ;
    ROM_SHAMD5Reset(SHAMD5_BASE);
    ROM_SHAMD5ConfigSet(SHAMD5_BASE, algo);
    ROM_SHAMD5DataProcess(SHAMD5_BASE, 
                   (uint32_t *)hash->msg, hash->used, h);
    wolfSSL_TI_unlockCCM() ;
#else
    (void) hash ;
    (void) algo ;
#endif
    XMEMCPY(result, h, hsize) ;

    return 0 ;
}
Esempio n. 3
0
static int  DesCbcAlign16(Des* des, byte* out, const byte* in, word32 sz, word32 dir, word32 tri)
{   

    wolfSSL_TI_lockCCM() ;
    ROM_DESReset(DES_BASE);
    ROM_DESConfigSet(DES_BASE, (dir | DES_CFG_MODE_CBC | tri));
    ROM_DESIVSet(DES_BASE, (uint32_t*)des->reg);
    ROM_DESKeySet(DES_BASE,(uint32_t*)des->key);
    if(dir == DES_CFG_DIR_DECRYPT)
        /* if input and output same will overwrite input iv */
        XMEMCPY(des->tmp, in + sz - DES_BLOCK_SIZE, DES_BLOCK_SIZE);
    ROM_DESDataProcess(DES_BASE, (uint32_t *)in, (uint32_t *)out, sz);
    wolfSSL_TI_unlockCCM() ;
    
    /* store iv for next call */
    if(dir == DES_CFG_DIR_ENCRYPT)
        XMEMCPY(des->reg, out + sz - DES_BLOCK_SIZE, DES_BLOCK_SIZE);
    else
        XMEMCPY(des->reg, des->tmp, DES_BLOCK_SIZE);
    
    return 0 ;
}