Changeset a35b458 in mainline for uspace/lib/crypto/aes.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/crypto/aes.c

    r3061bc1 ra35b458  
    213213        uint8_t i = byte >> 4;
    214214        uint8_t j = byte & 0xF;
    215        
     215
    216216        if (!inv)
    217217                return sbox[i][j];
    218        
     218
    219219        return inv_sbox[i][j];
    220220}
     
    229229{
    230230        uint8_t val;
    231        
     231
    232232        for (size_t i = 0; i < ELEMS; i++) {
    233233                for (size_t j = 0; j < ELEMS; j++) {
     
    246246{
    247247        uint8_t temp[ELEMS];
    248        
     248
    249249        for (size_t i = 1; i < ELEMS; i++) {
    250250                memcpy(temp, state[i], i);
     
    262262{
    263263        uint8_t temp[ELEMS];
    264        
     264
    265265        for (size_t i = 1; i < ELEMS; i++) {
    266266                memcpy(temp, state[i], ELEMS - i);
     
    282282        uint8_t result = 0;
    283283        uint8_t f_bith;
    284        
     284
    285285        for (size_t i = 0; i < 8; i++) {
    286286                if (y & 1)
    287287                        result ^= x;
    288                
     288
    289289                f_bith = (x & 0x80);
    290290                x <<= 1;
    291                
     291
    292292                if (f_bith)
    293293                        x ^= AES_IP;
    294                
     294
    295295                y >>= 1;
    296296        }
    297        
     297
    298298        return result;
    299299}
     
    308308        uint8_t orig_state[ELEMS][ELEMS];
    309309        memcpy(orig_state, state, BLOCK_LEN);
    310        
     310
    311311        for (size_t j = 0; j < ELEMS; j++) {
    312312                state[0][j] =
     
    342342        uint8_t orig_state[ELEMS][ELEMS];
    343343        memcpy(orig_state, state, BLOCK_LEN);
    344        
     344
    345345        for (size_t j = 0; j < ELEMS; j++) {
    346346                state[0][j] =
     
    378378        uint8_t shift;
    379379        uint32_t mask = 0xff;
    380        
     380
    381381        for (size_t j = 0; j < ELEMS; j++) {
    382382                for (size_t i = 0; i < ELEMS; i++) {
     
    399399        uint32_t temp = word;
    400400        uint8_t *start = (uint8_t *) &temp;
    401        
     401
    402402        for (size_t i = 0; i < 4; i++)
    403403                *(start + i) = sub_byte(*(start + i), false);
    404        
     404
    405405        return temp;
    406406}
     
    427427{
    428428        uint32_t temp;
    429        
     429
    430430        for (size_t i = 0; i < CIPHER_ELEMS; i++) {
    431431                key_exp[i] =
     
    435435                    (key[4 * i + 3]);
    436436        }
    437        
     437
    438438        for (size_t i = CIPHER_ELEMS; i < ELEMS * (ROUNDS + 1); i++) {
    439439                temp = key_exp[i - 1];
    440                
     440
    441441                if ((i % CIPHER_ELEMS) == 0) {
    442442                        temp = sub_word(rot_word(temp)) ^
    443443                            r_con_array[i / CIPHER_ELEMS - 1];
    444444                }
    445                
     445
    446446                key_exp[i] = key_exp[i - CIPHER_ELEMS] ^ temp;
    447447        }
     
    463463        if ((!key) || (!input))
    464464                return EINVAL;
    465        
     465
    466466        if (!output)
    467467                return ENOMEM;
    468        
     468
    469469        /* Create key expansion. */
    470470        uint32_t key_exp[ELEMS * (ROUNDS + 1)];
    471471        key_expansion(key, key_exp);
    472        
     472
    473473        /* Copy input into state array. */
    474474        uint8_t state[ELEMS][ELEMS];
     
    477477                        state[i][j] = input[i + ELEMS * j];
    478478        }
    479        
     479
    480480        /* Processing loop. */
    481481        add_round_key(state, key_exp);
    482        
     482
    483483        for (size_t k = 1; k <= ROUNDS; k++) {
    484484                sub_bytes(state, false);
    485485                shift_rows(state);
    486                
     486
    487487                if (k < ROUNDS)
    488488                        mix_columns(state);
    489                
     489
    490490                add_round_key(state, key_exp + k * ELEMS);
    491491        }
    492        
     492
    493493        /* Copy state array into output. */
    494494        for (size_t i = 0; i < ELEMS; i++) {
     
    496496                        output[i + j * ELEMS] = state[i][j];
    497497        }
    498        
     498
    499499        return EOK;
    500500}
     
    515515        if ((!key) || (!input))
    516516                return EINVAL;
    517        
     517
    518518        if (!output)
    519519                return ENOMEM;
    520        
     520
    521521        /* Create key expansion. */
    522522        uint32_t key_exp[ELEMS * (ROUNDS + 1)];
    523523        key_expansion(key, key_exp);
    524        
     524
    525525        /* Copy input into state array. */
    526526        uint8_t state[ELEMS][ELEMS];
     
    529529                        state[i][j] = input[i + ELEMS * j];
    530530        }
    531        
     531
    532532        /* Processing loop. */
    533533        add_round_key(state, key_exp + ROUNDS * ELEMS);
    534        
     534
    535535        for (int k = ROUNDS - 1; k >= 0; k--) {
    536536                inv_shift_rows(state);
    537537                sub_bytes(state, true);
    538538                add_round_key(state, key_exp + k * ELEMS);
    539                
     539
    540540                if (k > 0)
    541541                        inv_mix_columns(state);
    542542        }
    543        
     543
    544544        /* Copy state array into output. */
    545545        for (size_t i = 0; i < ELEMS; i++) {
     
    547547                        output[i + j * ELEMS] = state[i][j];
    548548        }
    549        
     549
    550550        return EOK;
    551551}
Note: See TracChangeset for help on using the changeset viewer.