Blame view

RIOT/sys/crypto/ciphers.c 1.12 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  /*
   * Copyright (C) 2015 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /*
   * @ingroup sys_crypto
   * @{
   * @file   ciphers.c
   * @author Nico von Geyso <nico.geyso@fu-berlin.de>
   * @}
   */
  
  #include <string.h>
  #include <stdio.h>
  #include "crypto/ciphers.h"
  
  
  int cipher_init(cipher_t* cipher, cipher_id_t cipher_id, const uint8_t* key,
                  uint8_t key_size)
  {
      if (key_size > cipher_id->max_key_size) {
          return CIPHER_ERR_INVALID_KEY_SIZE;
      }
  
      cipher->interface = cipher_id;
      return cipher->interface->init(&cipher->context, key, key_size);
  
  }
  
  
  int cipher_encrypt(const cipher_t* cipher, const uint8_t* input, uint8_t* output)
  {
      return cipher->interface->encrypt(&cipher->context, input, output);
  }
  
  
  int cipher_decrypt(const cipher_t* cipher, const uint8_t* input, uint8_t* output)
  {
      return cipher->interface->decrypt(&cipher->context, input, output);
  }
  
  
  int cipher_get_block_size(const cipher_t* cipher)
  {
      return cipher->interface->block_size;
  }