Changeset 8a64320e in mainline for uspace/lib/crypto/rc4.c


Ignore:
Timestamp:
2015-04-23T23:40:14Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dcba819
Parents:
09044cb
Message:

pre-merge coding style cleanup and code review

File:
1 edited

Legend:

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

    r09044cb r8a64320e  
    2828
    2929/** @file rc4.c
    30  * 
     30 *
    3131 * Implementation of ARC4 symmetric cipher cryptographic algorithm.
    32  * 
     32 *
    3333 */
    3434
    3535#include <errno.h>
    3636#include <mem.h>
    37 
    3837#include "crypto.h"
    3938
    4039/* Sbox table size. */
    41 #define SBOX_SIZE 256
     40#define SBOX_SIZE  256
    4241
    43 /**
    44  * Swap two values in sbox.
    45  *
    46  * @param i First index of value in sbox to be swapped.
    47  * @param j Second index of value in sbox to be swapped.
     42/** Swap two values in sbox.
     43 *
     44 * @param i    First index of value in sbox to be swapped.
     45 * @param j    Second index of value in sbox to be swapped.
    4846 * @param sbox Sbox to be modified.
     47 *
    4948 */
    5049static void swap(size_t i, size_t j, uint8_t *sbox)
     
    5554}
    5655
    57 /**
    58  * Sbox initialization procedure.
    59  *
    60  * @param key Input key.
     56/** Sbox initialization procedure.
     57 *
     58 * @param key      Input key.
    6159 * @param key_size Size of key sequence.
    62  * @param sbox Place for result sbox.
     60 * @param sbox     Place for result sbox.
     61 *
    6362 */
    6463static void create_sbox(uint8_t *key, size_t key_size, uint8_t *sbox)
    6564{
    66         for(size_t i = 0; i < SBOX_SIZE; i++) {
     65        for (size_t i = 0; i < SBOX_SIZE; i++)
    6766                sbox[i] = i;
    68         }
    6967       
    7068        uint8_t j = 0;
    71         for(size_t i = 0; i < SBOX_SIZE; i++) {
     69        for (size_t i = 0; i < SBOX_SIZE; i++) {
    7270                j = j + sbox[i] + key[i % key_size];
    7371                swap(i, j, sbox);
     
    7573}
    7674
    77 /**
    78  * ARC4 encryption/decryption algorithm.
    79  *
    80  * @param key Input key.
    81  * @param key_size Size of key sequence.
    82  * @param input Input data sequence to be processed.
     75/** ARC4 encryption/decryption algorithm.
     76 *
     77 * @param key        Input key.
     78 * @param key_size   Size of key sequence.
     79 * @param input      Input data sequence to be processed.
    8380 * @param input_size Size of input data sequence.
    84  * @param skip Number of bytes to be skipped from the beginning of key stream.
    85  * @param output Result data sequence.
    86  *
    87  * @return EINVAL when input or key not specified, ENOMEM when pointer for
    88  * output is not allocated, otherwise EOK. 
     81 * @param skip       Number of bytes to be skipped from
     82 *                   the beginning of key stream.
     83 * @param output     Result data sequence.
     84 *
     85 * @return EINVAL when input or key not specified,
     86 *         ENOMEM when pointer for output is not allocated,
     87 *         otherwise EOK.
     88 *
    8989 */
    90 int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size, 
    91         size_t skip, uint8_t *output)
     90int rc4(uint8_t *key, size_t key_size, uint8_t *input, size_t input_size,
     91    size_t skip, uint8_t *output)
    9292{
    93         if(!key || !input)
     93        if ((!key) || (!input))
    9494                return EINVAL;
    9595       
    96         if(!output)
     96        if (!output)
    9797                return ENOMEM;
    9898       
     
    102102       
    103103        /* Skip first x bytes. */
    104         uint8_t i = 0, j = 0;
    105         for(size_t k = 0; k < skip; k++) {
     104        uint8_t i = 0;
     105        uint8_t j = 0;
     106        for (size_t k = 0; k < skip; k++) {
    106107                i = i + 1;
    107108                j = j + sbox[i];
     
    111112        /* Processing loop. */
    112113        uint8_t val;
    113         for(size_t k = 0; k < input_size; k++) {
     114        for (size_t k = 0; k < input_size; k++) {
    114115                i = i + 1;
    115116                j = j + sbox[i];
Note: See TracChangeset for help on using the changeset viewer.