Ignore:
Timestamp:
Mar 15, 2016 3:57:39 AM (8 years ago)
Author:
nanang
Message:

Close #1847: Upgraded libsrtp version to 1.5.4 and added support for AES-CM-256 crypto.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/third_party/srtp/crypto/cipher/aes.c

    r1730 r5261  
    4444 */ 
    4545 
     46#ifdef HAVE_CONFIG_H 
     47    #include <config.h> 
     48#endif 
    4649 
    4750#include "aes.h" 
     
    13591362extern debug_module_t mod_aes_icm; 
    13601363 
    1361 void 
    1362 aes_expand_encryption_key(const v128_t *key,  
    1363                           aes_expanded_key_t expanded_key) { 
     1364static void 
     1365aes_128_expand_encryption_key(const uint8_t *key,  
     1366                              aes_expanded_key_t *expanded_key) { 
    13641367  int i; 
    13651368  gf2_8 rc; 
     
    13681371  rc = 1; 
    13691372 
    1370   expanded_key[0].v32[0] = key->v32[0]; 
    1371   expanded_key[0].v32[1] = key->v32[1]; 
    1372   expanded_key[0].v32[2] = key->v32[2]; 
    1373   expanded_key[0].v32[3] = key->v32[3]; 
     1373  expanded_key->num_rounds = 10; 
     1374 
     1375  v128_copy_octet_string(&expanded_key->round[0], key); 
    13741376 
    13751377#if 0 
    13761378  debug_print(mod_aes_icm,  
    1377               "expanded key[0]:  %s", v128_hex_string(&expanded_key[0]));  
     1379              "expanded key[0]:  %s", v128_hex_string(&expanded_key->round[0]));  
    13781380#endif 
    13791381 
     
    13821384 
    13831385    /* munge first word of round key */ 
    1384     expanded_key[i].v8[0] = aes_sbox[expanded_key[i-1].v8[13]] ^ rc; 
    1385     expanded_key[i].v8[1] = aes_sbox[expanded_key[i-1].v8[14]]; 
    1386     expanded_key[i].v8[2] = aes_sbox[expanded_key[i-1].v8[15]]; 
    1387     expanded_key[i].v8[3] = aes_sbox[expanded_key[i-1].v8[12]]; 
    1388  
    1389     expanded_key[i].v32[0] ^=  expanded_key[i-1].v32[0]; 
     1386    expanded_key->round[i].v8[0] = aes_sbox[expanded_key->round[i-1].v8[13]] ^ rc; 
     1387    expanded_key->round[i].v8[1] = aes_sbox[expanded_key->round[i-1].v8[14]]; 
     1388    expanded_key->round[i].v8[2] = aes_sbox[expanded_key->round[i-1].v8[15]]; 
     1389    expanded_key->round[i].v8[3] = aes_sbox[expanded_key->round[i-1].v8[12]]; 
     1390 
     1391    expanded_key->round[i].v32[0] ^=  expanded_key->round[i-1].v32[0]; 
    13901392 
    13911393    /* set remaining 32 bit words to the exor of the one previous with 
    13921394     * the one four words previous */ 
    13931395 
    1394     expanded_key[i].v32[1] = 
    1395       expanded_key[i].v32[0] ^ expanded_key[i-1].v32[1]; 
    1396  
    1397     expanded_key[i].v32[2] = 
    1398       expanded_key[i].v32[1] ^ expanded_key[i-1].v32[2]; 
    1399  
    1400     expanded_key[i].v32[3] = 
    1401       expanded_key[i].v32[2] ^ expanded_key[i-1].v32[3]; 
     1396    expanded_key->round[i].v32[1] = 
     1397      expanded_key->round[i].v32[0] ^ expanded_key->round[i-1].v32[1]; 
     1398 
     1399    expanded_key->round[i].v32[2] = 
     1400      expanded_key->round[i].v32[1] ^ expanded_key->round[i-1].v32[2]; 
     1401 
     1402    expanded_key->round[i].v32[3] = 
     1403      expanded_key->round[i].v32[2] ^ expanded_key->round[i-1].v32[3]; 
    14021404 
    14031405#if 0 
    14041406        debug_print2(mod_aes_icm,  
    1405                                 "expanded key[%d]:  %s", i,v128_hex_string(&expanded_key[i]));  
     1407                                "expanded key[%d]:  %s", i,v128_hex_string(&expanded_key->round[i]));  
    14061408#endif 
    14071409 
     
    14121414} 
    14131415 
    1414 void 
    1415 aes_expand_decryption_key(const v128_t *key,  
    1416                           aes_expanded_key_t expanded_key) { 
     1416static void 
     1417aes_256_expand_encryption_key(const unsigned char *key,  
     1418                              aes_expanded_key_t *expanded_key) { 
    14171419  int i; 
    1418  
    1419   aes_expand_encryption_key(key, expanded_key); 
     1420  gf2_8 rc; 
     1421 
     1422  /* initialize round constant */ 
     1423  rc = 1; 
     1424 
     1425  expanded_key->num_rounds = 14; 
     1426 
     1427  v128_copy_octet_string(&expanded_key->round[0], key); 
     1428  v128_copy_octet_string(&expanded_key->round[1], key+16); 
     1429 
     1430#if 0 
     1431  debug_print(mod_aes_icm,  
     1432              "expanded key[0]:  %s", v128_hex_string(&expanded_key->round[0]));  
     1433  debug_print(mod_aes_icm,  
     1434              "expanded key[1]:  %s", v128_hex_string(&expanded_key->round[1]));  
     1435#endif 
     1436 
     1437  /* loop over rest of round keys */ 
     1438  for (i=2; i < 15; i++) { 
     1439 
     1440    /* munge first word of round key */ 
     1441    if ((i & 1) == 0) { 
     1442      expanded_key->round[i].v8[0] = aes_sbox[expanded_key->round[i-1].v8[13]] ^ rc; 
     1443      expanded_key->round[i].v8[1] = aes_sbox[expanded_key->round[i-1].v8[14]]; 
     1444      expanded_key->round[i].v8[2] = aes_sbox[expanded_key->round[i-1].v8[15]]; 
     1445      expanded_key->round[i].v8[3] = aes_sbox[expanded_key->round[i-1].v8[12]]; 
     1446 
     1447      /* modify round constant */ 
     1448      rc = gf2_8_shift(rc); 
     1449    } 
     1450    else { 
     1451      expanded_key->round[i].v8[0] = aes_sbox[expanded_key->round[i-1].v8[12]]; 
     1452      expanded_key->round[i].v8[1] = aes_sbox[expanded_key->round[i-1].v8[13]]; 
     1453      expanded_key->round[i].v8[2] = aes_sbox[expanded_key->round[i-1].v8[14]]; 
     1454      expanded_key->round[i].v8[3] = aes_sbox[expanded_key->round[i-1].v8[15]]; 
     1455    } 
     1456 
     1457    expanded_key->round[i].v32[0] ^=  expanded_key->round[i-2].v32[0]; 
     1458 
     1459    /* set remaining 32 bit words to the exor of the one previous with 
     1460     * the one eight words previous */ 
     1461 
     1462    expanded_key->round[i].v32[1] = 
     1463      expanded_key->round[i].v32[0] ^ expanded_key->round[i-2].v32[1]; 
     1464 
     1465    expanded_key->round[i].v32[2] = 
     1466      expanded_key->round[i].v32[1] ^ expanded_key->round[i-2].v32[2]; 
     1467 
     1468    expanded_key->round[i].v32[3] = 
     1469      expanded_key->round[i].v32[2] ^ expanded_key->round[i-2].v32[3]; 
     1470 
     1471#if 0 
     1472    debug_print2(mod_aes_icm,  
     1473                 "expanded key[%d]:  %s", i,v128_hex_string(&expanded_key->round[i]));  
     1474#endif 
     1475 
     1476  } 
     1477} 
     1478 
     1479err_status_t 
     1480aes_expand_encryption_key(const uint8_t *key,  
     1481                          int key_len, 
     1482                          aes_expanded_key_t *expanded_key) { 
     1483  if (key_len == 16) { 
     1484    aes_128_expand_encryption_key(key, expanded_key); 
     1485    return err_status_ok; 
     1486  } 
     1487  else if (key_len == 24) { 
     1488    /* AES-192 not yet supported */ 
     1489    return err_status_bad_param; 
     1490  } 
     1491  else if (key_len == 32) { 
     1492    aes_256_expand_encryption_key(key, expanded_key); 
     1493    return err_status_ok; 
     1494  } 
     1495  else 
     1496    return err_status_bad_param; 
     1497} 
     1498 
     1499err_status_t 
     1500aes_expand_decryption_key(const uint8_t *key,  
     1501                          int key_len, 
     1502                          aes_expanded_key_t *expanded_key) { 
     1503  int i; 
     1504  err_status_t status; 
     1505  int num_rounds = expanded_key->num_rounds; 
     1506 
     1507  status = aes_expand_encryption_key(key, key_len, expanded_key); 
     1508  if (status) 
     1509    return status; 
    14201510 
    14211511  /* invert the order of the round keys */ 
    1422   for (i=0; i < 5; i++) { 
     1512  for (i=0; i < num_rounds/2; i++) { 
    14231513    v128_t tmp; 
    1424     v128_copy(&tmp, &expanded_key[10-i]); 
    1425     v128_copy(&expanded_key[10-i], &expanded_key[i]); 
    1426     v128_copy(&expanded_key[i], &tmp); 
     1514    v128_copy(&tmp, &expanded_key->round[num_rounds-i]); 
     1515    v128_copy(&expanded_key->round[num_rounds-i], &expanded_key->round[i]); 
     1516    v128_copy(&expanded_key->round[i], &tmp); 
    14271517  } 
    14281518 
     
    14351525   * in the U-tables) 
    14361526   */ 
    1437   for (i=1; i < 10; i++) { 
     1527  for (i=1; i < num_rounds; i++) { 
    14381528#ifdef CPU_RISC 
    14391529    uint32_t tmp; 
    14401530 
    1441     tmp = expanded_key[i].v32[0]; 
    1442     expanded_key[i].v32[0] =  
     1531#ifdef WORDS_BIGENDIAN 
     1532    tmp = expanded_key->round[i].v32[0]; 
     1533    expanded_key->round[i].v32[0] =  
    14431534      U0[T4[(tmp >> 24)       ] & 0xff] ^  
    14441535      U1[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     
    14461537      U3[T4[(tmp)       & 0xff] & 0xff]; 
    14471538 
    1448     tmp = expanded_key[i].v32[1]; 
    1449     expanded_key[i].v32[1] =  
     1539    tmp = expanded_key->round[i].v32[1]; 
     1540    expanded_key->round[i].v32[1] =  
    14501541      U0[T4[(tmp >> 24)       ] & 0xff] ^  
    14511542      U1[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     
    14531544      U3[T4[(tmp)       & 0xff] & 0xff]; 
    14541545 
    1455     tmp = expanded_key[i].v32[2]; 
    1456     expanded_key[i].v32[2] =  
     1546    tmp = expanded_key->round[i].v32[2]; 
     1547    expanded_key->round[i].v32[2] =  
    14571548      U0[T4[(tmp >> 24)       ] & 0xff] ^  
    14581549      U1[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     
    14601551      U3[T4[(tmp)       & 0xff] & 0xff]; 
    14611552 
    1462     tmp = expanded_key[i].v32[3]; 
    1463     expanded_key[i].v32[3] =  
     1553    tmp = expanded_key->round[i].v32[3]; 
     1554    expanded_key->round[i].v32[3] =  
    14641555      U0[T4[(tmp >> 24)       ] & 0xff] ^  
    14651556      U1[T4[(tmp >> 16) & 0xff] & 0xff] ^  
    14661557      U2[T4[(tmp >> 8)  & 0xff] & 0xff] ^  
    14671558      U3[T4[(tmp)       & 0xff] & 0xff]; 
     1559#else 
     1560    tmp = expanded_key->round[i].v32[0]; 
     1561    expanded_key->round[i].v32[0] =  
     1562      U3[T4[(tmp >> 24)       ] & 0xff] ^  
     1563      U2[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     1564      U1[T4[(tmp >> 8)  & 0xff] & 0xff] ^  
     1565      U0[T4[(tmp)       & 0xff] & 0xff]; 
     1566 
     1567    tmp = expanded_key->round[i].v32[1]; 
     1568    expanded_key->round[i].v32[1] =  
     1569      U3[T4[(tmp >> 24)       ] & 0xff] ^  
     1570      U2[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     1571      U1[T4[(tmp >> 8)  & 0xff] & 0xff] ^  
     1572      U0[T4[(tmp)       & 0xff] & 0xff]; 
     1573 
     1574    tmp = expanded_key->round[i].v32[2]; 
     1575    expanded_key->round[i].v32[2] =  
     1576      U3[T4[(tmp >> 24)       ] & 0xff] ^  
     1577      U2[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     1578      U1[T4[(tmp >> 8)  & 0xff] & 0xff] ^  
     1579      U0[T4[(tmp)       & 0xff] & 0xff]; 
     1580 
     1581    tmp = expanded_key->round[i].v32[3]; 
     1582    expanded_key->round[i].v32[3] =  
     1583      U3[T4[(tmp >> 24)       ] & 0xff] ^  
     1584      U2[T4[(tmp >> 16) & 0xff] & 0xff] ^  
     1585      U1[T4[(tmp >> 8)  & 0xff] & 0xff] ^  
     1586      U0[T4[(tmp)       & 0xff] & 0xff]; 
     1587#endif /* WORDS_BIGENDIAN */ 
     1588 
    14681589#else /* assume CPU_CISC */ 
    14691590 
    14701591    uint32_t c0, c1, c2, c3; 
    14711592 
    1472     c0 = U0[aes_sbox[expanded_key[i].v8[0]]]  
    1473        ^ U1[aes_sbox[expanded_key[i].v8[1]]]  
    1474        ^ U2[aes_sbox[expanded_key[i].v8[2]]]  
    1475        ^ U3[aes_sbox[expanded_key[i].v8[3]]]; 
    1476  
    1477     c1 = U0[aes_sbox[expanded_key[i].v8[4]]]  
    1478        ^ U1[aes_sbox[expanded_key[i].v8[5]]]  
    1479        ^ U2[aes_sbox[expanded_key[i].v8[6]]]  
    1480        ^ U3[aes_sbox[expanded_key[i].v8[7]]]; 
    1481  
    1482     c2 = U0[aes_sbox[expanded_key[i].v8[8]]]  
    1483        ^ U1[aes_sbox[expanded_key[i].v8[9]]]  
    1484        ^ U2[aes_sbox[expanded_key[i].v8[10]]]  
    1485        ^ U3[aes_sbox[expanded_key[i].v8[11]]]; 
    1486  
    1487     c3 = U0[aes_sbox[expanded_key[i].v8[12]]]  
    1488        ^ U1[aes_sbox[expanded_key[i].v8[13]]]  
    1489        ^ U2[aes_sbox[expanded_key[i].v8[14]]]  
    1490        ^ U3[aes_sbox[expanded_key[i].v8[15]]]; 
    1491  
    1492     expanded_key[i].v32[0] = c0; 
    1493     expanded_key[i].v32[1] = c1; 
    1494     expanded_key[i].v32[2] = c2; 
    1495     expanded_key[i].v32[3] = c3; 
     1593    c0 = U0[aes_sbox[expanded_key->round[i].v8[0]]]  
     1594       ^ U1[aes_sbox[expanded_key->round[i].v8[1]]]  
     1595       ^ U2[aes_sbox[expanded_key->round[i].v8[2]]]  
     1596       ^ U3[aes_sbox[expanded_key->round[i].v8[3]]]; 
     1597 
     1598    c1 = U0[aes_sbox[expanded_key->round[i].v8[4]]]  
     1599       ^ U1[aes_sbox[expanded_key->round[i].v8[5]]]  
     1600       ^ U2[aes_sbox[expanded_key->round[i].v8[6]]]  
     1601       ^ U3[aes_sbox[expanded_key->round[i].v8[7]]]; 
     1602 
     1603    c2 = U0[aes_sbox[expanded_key->round[i].v8[8]]]  
     1604       ^ U1[aes_sbox[expanded_key->round[i].v8[9]]]  
     1605       ^ U2[aes_sbox[expanded_key->round[i].v8[10]]]  
     1606       ^ U3[aes_sbox[expanded_key->round[i].v8[11]]]; 
     1607 
     1608    c3 = U0[aes_sbox[expanded_key->round[i].v8[12]]]  
     1609       ^ U1[aes_sbox[expanded_key->round[i].v8[13]]]  
     1610       ^ U2[aes_sbox[expanded_key->round[i].v8[14]]]  
     1611       ^ U3[aes_sbox[expanded_key->round[i].v8[15]]]; 
     1612 
     1613    expanded_key->round[i].v32[0] = c0; 
     1614    expanded_key->round[i].v32[1] = c1; 
     1615    expanded_key->round[i].v32[2] = c2; 
     1616    expanded_key->round[i].v32[3] = c3; 
    14961617 
    14971618#endif      
    14981619  } 
     1620 
     1621  return err_status_ok; 
    14991622} 
    15001623 
     
    16771800 
    16781801#ifdef WORDS_BIGENDIAN 
    1679   /* FIX!  WRong indexes */ 
    16801802  column0 = U0[state->v32[0] >> 24] ^ U1[(state->v32[3] >> 16) & 0xff] 
    16811803    ^ U2[(state->v32[2] >> 8) & 0xff] ^ U3[state->v32[1] & 0xff]; 
     
    16901812    ^ U2[(state->v32[1] >> 8) & 0xff] ^ U3[state->v32[0] & 0xff]; 
    16911813#else 
    1692   column0 = U0[state->v32[0] & 0xff] ^ U1[(state->v32[1] >> 8) & 0xff] 
    1693         ^ U2[(state->v32[2] >> 16) & 0xff] ^ U3[state->v32[3] >> 24]; 
    1694  
    1695   column1 = U0[state->v32[1] & 0xff] ^ U1[(state->v32[2] >> 8) & 0xff] 
    1696         ^ U2[(state->v32[3] >> 16) & 0xff] ^ U3[state->v32[0] >> 24]; 
    1697  
    1698   column2 = U0[state->v32[2] & 0xff] ^ U1[(state->v32[3] >> 8) & 0xff] 
    1699         ^ U2[(state->v32[0] >> 16) & 0xff] ^ U3[state->v32[1] >> 24]; 
    1700  
    1701   column3 = U0[state->v32[3] & 0xff] ^ U1[(state->v32[0] >> 8) & 0xff] 
    1702         ^ U2[(state->v32[1] >> 16) & 0xff] ^ U3[state->v32[2] >> 24]; 
     1814  column0 = U0[state->v32[0] & 0xff] ^ U1[(state->v32[3] >> 8) & 0xff] 
     1815    ^ U2[(state->v32[2] >> 16) & 0xff] ^ U3[(state->v32[1] >> 24) & 0xff]; 
     1816 
     1817  column1 = U0[state->v32[1] & 0xff] ^ U1[(state->v32[0] >> 8) & 0xff] 
     1818    ^ U2[(state->v32[3] >> 16) & 0xff] ^ U3[(state->v32[2] >> 24) & 0xff]; 
     1819 
     1820  column2 = U0[state->v32[2] & 0xff] ^ U1[(state->v32[1] >> 8) & 0xff] 
     1821    ^ U2[(state->v32[0] >> 16) & 0xff] ^ U3[(state->v32[3] >> 24) & 0xff]; 
     1822 
     1823  column3 = U0[state->v32[3] & 0xff] ^ U1[(state->v32[2] >> 8) & 0xff] 
     1824    ^ U2[(state->v32[1] >> 16) & 0xff] ^ U3[(state->v32[0] >> 24) & 0xff]; 
    17031825#endif /* WORDS_BIGENDIAN */ 
    17041826 
     
    17141836  uint32_t tmp0, tmp1, tmp2, tmp3; 
    17151837 
     1838#ifdef WORDS_BIGENDIAN 
    17161839  tmp0 = (T4[(state->v32[0] >> 24)]        & 0xff000000)  
    17171840       ^ (T4[(state->v32[1] >> 16) & 0xff] & 0x00ff0000)  
     
    17371860       ^ (T4[(state->v32[2]      ) & 0xff] & 0x000000ff) 
    17381861       ^ round_key->v32[3]; 
     1862#else 
     1863  tmp0 = (T4[(state->v32[3] >> 24)]        & 0xff000000)  
     1864       ^ (T4[(state->v32[2] >> 16) & 0xff] & 0x00ff0000)  
     1865       ^ (T4[(state->v32[1] >>  8) & 0xff] & 0x0000ff00)  
     1866       ^ (T4[(state->v32[0]      ) & 0xff] & 0x000000ff)  
     1867       ^ round_key->v32[0]; 
     1868 
     1869  tmp1 = (T4[(state->v32[0] >> 24)]        & 0xff000000) 
     1870       ^ (T4[(state->v32[3] >> 16) & 0xff] & 0x00ff0000) 
     1871       ^ (T4[(state->v32[2] >>  8) & 0xff] & 0x0000ff00) 
     1872       ^ (T4[(state->v32[1]      ) & 0xff] & 0x000000ff) 
     1873       ^ round_key->v32[1]; 
     1874 
     1875  tmp2 = (T4[(state->v32[1] >> 24)]        & 0xff000000) 
     1876       ^ (T4[(state->v32[0] >> 16) & 0xff] & 0x00ff0000) 
     1877       ^ (T4[(state->v32[3] >>  8) & 0xff] & 0x0000ff00) 
     1878       ^ (T4[(state->v32[2]      ) & 0xff] & 0x000000ff) 
     1879       ^ round_key->v32[2]; 
     1880 
     1881  tmp3 = (T4[(state->v32[2] >> 24)]        & 0xff000000) 
     1882       ^ (T4[(state->v32[1] >> 16) & 0xff] & 0x00ff0000) 
     1883       ^ (T4[(state->v32[0] >>  8) & 0xff] & 0x0000ff00) 
     1884       ^ (T4[(state->v32[3]      ) & 0xff] & 0x000000ff) 
     1885       ^ round_key->v32[3]; 
     1886#endif /* WORDS_BIGENDIAN */ 
    17391887 
    17401888  state->v32[0] = tmp0; 
     
    17491897  uint32_t tmp0, tmp1, tmp2, tmp3; 
    17501898 
     1899#ifdef WORDS_BIGENDIAN 
    17511900  tmp0 = (U4[(state->v32[0] >> 24)]        & 0xff000000)  
    17521901       ^ (U4[(state->v32[3] >> 16) & 0xff] & 0x00ff0000)  
     
    17721921       ^ (U4[(state->v32[0]      ) & 0xff] & 0x000000ff) 
    17731922       ^ round_key->v32[3]; 
     1923#else 
     1924  tmp0 = (U4[(state->v32[1] >> 24)]        & 0xff000000)  
     1925       ^ (U4[(state->v32[2] >> 16) & 0xff] & 0x00ff0000)  
     1926       ^ (U4[(state->v32[3] >>  8) & 0xff] & 0x0000ff00)  
     1927       ^ (U4[(state->v32[0]      ) & 0xff] & 0x000000ff)  
     1928       ^ round_key->v32[0]; 
     1929 
     1930  tmp1 = (U4[(state->v32[2] >> 24)]        & 0xff000000) 
     1931       ^ (U4[(state->v32[3] >> 16) & 0xff] & 0x00ff0000) 
     1932       ^ (U4[(state->v32[0] >>  8) & 0xff] & 0x0000ff00) 
     1933       ^ (U4[(state->v32[1]      ) & 0xff] & 0x000000ff) 
     1934       ^ round_key->v32[1]; 
     1935 
     1936  tmp2 = (U4[(state->v32[3] >> 24)]        & 0xff000000) 
     1937       ^ (U4[(state->v32[0] >> 16) & 0xff] & 0x00ff0000) 
     1938       ^ (U4[(state->v32[1] >>  8) & 0xff] & 0x0000ff00) 
     1939       ^ (U4[(state->v32[2]      ) & 0xff] & 0x000000ff) 
     1940       ^ round_key->v32[2]; 
     1941 
     1942  tmp3 = (U4[(state->v32[0] >> 24)]        & 0xff000000) 
     1943       ^ (U4[(state->v32[1] >> 16) & 0xff] & 0x00ff0000) 
     1944       ^ (U4[(state->v32[2] >>  8) & 0xff] & 0x0000ff00) 
     1945       ^ (U4[(state->v32[3]      ) & 0xff] & 0x000000ff) 
     1946       ^ round_key->v32[3]; 
     1947#endif /* WORDS_BIGENDIAN */ 
    17741948 
    17751949  state->v32[0] = tmp0; 
     
    19112085 
    19122086void 
    1913 aes_encrypt(v128_t *plaintext, const aes_expanded_key_t exp_key) { 
     2087aes_encrypt(v128_t *plaintext, const aes_expanded_key_t *exp_key) { 
    19142088 
    19152089  /* add in the subkey */ 
    1916   v128_xor_eq(plaintext, exp_key + 0); 
    1917  
    1918   /* now do nine rounds */ 
    1919   aes_round(plaintext, exp_key + 1); 
    1920   aes_round(plaintext, exp_key + 2); 
    1921   aes_round(plaintext, exp_key + 3); 
    1922   aes_round(plaintext, exp_key + 4); 
    1923   aes_round(plaintext, exp_key + 5); 
    1924   aes_round(plaintext, exp_key + 6); 
    1925   aes_round(plaintext, exp_key + 7); 
    1926   aes_round(plaintext, exp_key + 8);   
    1927   aes_round(plaintext, exp_key + 9); 
    1928   /* the last round is different */ 
    1929  
    1930  aes_final_round(plaintext, exp_key + 10);   
     2090  v128_xor_eq(plaintext, &exp_key->round[0]); 
     2091 
     2092  /* now do the rounds */ 
     2093  aes_round(plaintext, &exp_key->round[1]); 
     2094  aes_round(plaintext, &exp_key->round[2]); 
     2095  aes_round(plaintext, &exp_key->round[3]); 
     2096  aes_round(plaintext, &exp_key->round[4]); 
     2097  aes_round(plaintext, &exp_key->round[5]); 
     2098  aes_round(plaintext, &exp_key->round[6]); 
     2099  aes_round(plaintext, &exp_key->round[7]); 
     2100  aes_round(plaintext, &exp_key->round[8]);   
     2101  aes_round(plaintext, &exp_key->round[9]); 
     2102  if (exp_key->num_rounds == 10) { 
     2103    aes_final_round(plaintext, &exp_key->round[10]); 
     2104  } 
     2105  else if (exp_key->num_rounds == 12) { 
     2106    aes_round(plaintext, &exp_key->round[10]);   
     2107    aes_round(plaintext, &exp_key->round[11]); 
     2108    aes_final_round(plaintext, &exp_key->round[12]); 
     2109  } 
     2110  else if (exp_key->num_rounds == 14) { 
     2111    aes_round(plaintext, &exp_key->round[10]);   
     2112    aes_round(plaintext, &exp_key->round[11]); 
     2113    aes_round(plaintext, &exp_key->round[12]);   
     2114    aes_round(plaintext, &exp_key->round[13]); 
     2115    aes_final_round(plaintext, &exp_key->round[14]);   
     2116  } 
    19312117} 
    19322118 
    19332119void 
    1934 aes_decrypt(v128_t *plaintext, const aes_expanded_key_t exp_key) { 
     2120aes_decrypt(v128_t *plaintext, const aes_expanded_key_t *exp_key) { 
    19352121 
    19362122  /* add in the subkey */ 
    1937   v128_xor_eq(plaintext, exp_key + 0); 
    1938  
    1939   /* now do nine rounds */ 
    1940   aes_inv_round(plaintext, exp_key + 1); 
    1941   aes_inv_round(plaintext, exp_key + 2); 
    1942   aes_inv_round(plaintext, exp_key + 3); 
    1943   aes_inv_round(plaintext, exp_key + 4); 
    1944   aes_inv_round(plaintext, exp_key + 5); 
    1945   aes_inv_round(plaintext, exp_key + 6); 
    1946   aes_inv_round(plaintext, exp_key + 7); 
    1947   aes_inv_round(plaintext, exp_key + 8);   
    1948   aes_inv_round(plaintext, exp_key + 9); 
    1949   /* the last round is different */ 
    1950   aes_inv_final_round(plaintext, exp_key + 10);   
     2123  v128_xor_eq(plaintext, &exp_key->round[0]); 
     2124 
     2125  /* now do the rounds */ 
     2126  aes_inv_round(plaintext, &exp_key->round[1]); 
     2127  aes_inv_round(plaintext, &exp_key->round[2]); 
     2128  aes_inv_round(plaintext, &exp_key->round[3]); 
     2129  aes_inv_round(plaintext, &exp_key->round[4]); 
     2130  aes_inv_round(plaintext, &exp_key->round[5]); 
     2131  aes_inv_round(plaintext, &exp_key->round[6]); 
     2132  aes_inv_round(plaintext, &exp_key->round[7]); 
     2133  aes_inv_round(plaintext, &exp_key->round[8]);   
     2134  aes_inv_round(plaintext, &exp_key->round[9]); 
     2135  if (exp_key->num_rounds == 10) { 
     2136    aes_inv_final_round(plaintext, &exp_key->round[10]);   
     2137  } 
     2138  else if (exp_key->num_rounds == 12) { 
     2139    aes_inv_round(plaintext, &exp_key->round[10]);   
     2140    aes_inv_round(plaintext, &exp_key->round[11]); 
     2141    aes_inv_final_round(plaintext, &exp_key->round[12]);   
     2142  } 
     2143  else if (exp_key->num_rounds == 14) { 
     2144    aes_inv_round(plaintext, &exp_key->round[10]);   
     2145    aes_inv_round(plaintext, &exp_key->round[11]); 
     2146    aes_inv_round(plaintext, &exp_key->round[12]);   
     2147    aes_inv_round(plaintext, &exp_key->round[13]); 
     2148    aes_inv_final_round(plaintext, &exp_key->round[14]);   
     2149  } 
    19512150} 
Note: See TracChangeset for help on using the changeset viewer.