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

randombit / botan / 21888402193

11 Feb 2026 12:53AM UTC coverage: 90.068% (-1.6%) from 91.638%
21888402193

push

github

web-flow
Merge pull request #5302 from randombit/jack/header-patrol-4

Cleanup various header inclusions

102229 of 113502 relevant lines covered (90.07%)

11489469.59 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/assert.h>
11
#include <botan/internal/ffi_util.h>
12

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

18
extern "C" {
19

20
using namespace Botan_FFI;
21

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

38
      std::vector<uint8_t> output;
2✔
39

40
      if(padded == 0) {
2✔
41
         output = Botan::nist_key_wrap(key, key_len, *bc);
4✔
42
      } else {
43
         output = Botan::nist_key_wrap_padded(key, key_len, *bc);
×
44
      }
45

46
      return write_vec_output(wrapped_key, wrapped_key_len, output);
2✔
47
   });
4✔
48
#else
49
   BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
50
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
51
#endif
52
}
53

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

68
      auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
2✔
69
      bc->set_key(kek, kek_len);
2✔
70

71
      Botan::secure_vector<uint8_t> output;
2✔
72

73
      if(padded == 0) {
2✔
74
         output = Botan::nist_key_unwrap(wrapped_key, wrapped_key_len, *bc);
4✔
75
      } else {
76
         output = Botan::nist_key_unwrap_padded(wrapped_key, wrapped_key_len, *bc);
×
77
      }
78

79
      return write_vec_output(key, key_len, output);
2✔
80
   });
4✔
81
#else
82
   BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
83
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
84
#endif
85
}
86

87
int botan_key_wrap3394(const uint8_t key[],
1✔
88
                       size_t key_len,
89
                       const uint8_t kek[],
90
                       size_t kek_len,
91
                       uint8_t wrapped_key[],
92
                       size_t* wrapped_key_len) {
93
   const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
2✔
94

95
   return botan_nist_kw_enc(cipher_name.c_str(), 0, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
1✔
96
}
1✔
97

98
int botan_key_unwrap3394(const uint8_t wrapped_key[],
1✔
99
                         size_t wrapped_key_len,
100
                         const uint8_t kek[],
101
                         size_t kek_len,
102
                         uint8_t key[],
103
                         size_t* key_len) {
104
   const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
2✔
105

106
   return botan_nist_kw_dec(cipher_name.c_str(), 0, wrapped_key, wrapped_key_len, kek, kek_len, key, key_len);
1✔
107
}
1✔
108
}
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