• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/lib/ffi/ffi_keywrap.cpp
1
/*
2
* (C) 2017 Ribose Inc
3
*     2023 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/ffi.h>
9

10
#include <botan/internal/ffi_util.h>
11

12
#if defined(BOTAN_HAS_NIST_KEYWRAP)
13
   #include <botan/block_cipher.h>
14
   #include <botan/nist_keywrap.h>
15
#endif
16

17
extern "C" {
18

19
using namespace Botan_FFI;
20

21
int botan_nist_kw_enc(const char* cipher_algo,
2✔
22
                      int padded,
23
                      const uint8_t key[],
24
                      size_t key_len,
25
                      const uint8_t kek[],
26
                      size_t kek_len,
27
                      uint8_t wrapped_key[],
28
                      size_t* wrapped_key_len) {
29
#if defined(BOTAN_HAS_NIST_KEYWRAP)
30
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
31
      if(padded != 0 && padded != 1)
2✔
32
         return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
33
      auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
2✔
34
      bc->set_key(kek, kek_len);
2✔
35

36
      std::vector<uint8_t> output;
2✔
37

38
      if(padded == 0)
2✔
39
         output = Botan::nist_key_wrap(key, key_len, *bc);
4✔
40
      else
41
         output = Botan::nist_key_wrap_padded(key, key_len, *bc);
×
42

43
      return write_vec_output(wrapped_key, wrapped_key_len, output);
2✔
44
   });
6✔
45
#else
46
   BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
47
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
48
#endif
49
}
50

51
int botan_nist_kw_dec(const char* cipher_algo,
2✔
52
                      int padded,
53
                      const uint8_t wrapped_key[],
54
                      size_t wrapped_key_len,
55
                      const uint8_t kek[],
56
                      size_t kek_len,
57
                      uint8_t key[],
58
                      size_t* key_len) {
59
#if defined(BOTAN_HAS_NIST_KEYWRAP)
60
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
61
      if(padded != 0 && padded != 1)
2✔
62
         return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
63

64
      auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
2✔
65
      bc->set_key(kek, kek_len);
2✔
66

67
      Botan::secure_vector<uint8_t> output;
2✔
68

69
      if(padded == 0)
2✔
70
         output = Botan::nist_key_unwrap(wrapped_key, wrapped_key_len, *bc);
4✔
71
      else
72
         output = Botan::nist_key_unwrap_padded(wrapped_key, wrapped_key_len, *bc);
×
73

74
      return write_vec_output(key, key_len, output);
2✔
75
   });
6✔
76
#else
77
   BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
78
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
79
#endif
80
}
81

82
int botan_key_wrap3394(const uint8_t key[],
1✔
83
                       size_t key_len,
84
                       const uint8_t kek[],
85
                       size_t kek_len,
86
                       uint8_t wrapped_key[],
87
                       size_t* wrapped_key_len) {
88
   std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
1✔
89

90
   return botan_nist_kw_enc(cipher_name.c_str(), 0, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
1✔
91
}
1✔
92

93
int botan_key_unwrap3394(const uint8_t wrapped_key[],
1✔
94
                         size_t wrapped_key_len,
95
                         const uint8_t kek[],
96
                         size_t kek_len,
97
                         uint8_t key[],
98
                         size_t* key_len) {
99
   std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
1✔
100

101
   return botan_nist_kw_dec(cipher_name.c_str(), 0, wrapped_key, wrapped_key_len, kek, kek_len, key, key_len);
1✔
102
}
1✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc