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

randombit / botan / 24063525848

06 Apr 2026 10:36PM UTC coverage: 89.448% (-0.007%) from 89.455%
24063525848

push

github

web-flow
Merge pull request #5521 from randombit/jack/fix-rollup

Rollup of small fixes

105878 of 118368 relevant lines covered (89.45%)

11475460.89 hits per line

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

93.75
/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(any_null_pointers(cipher_algo, key, kek)) {
2✔
31
      return BOTAN_FFI_ERROR_NULL_POINTER;
32
   }
33
#if defined(BOTAN_HAS_NIST_KEYWRAP)
34
   return ffi_guard_thunk(__func__, [=]() -> int {
2✔
35
      if(padded != 0 && padded != 1) {
2✔
36
         return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
37
      }
38
      auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
2✔
39
      bc->set_key(kek, kek_len);
2✔
40

41
      std::vector<uint8_t> output;
2✔
42

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

49
      return write_vec_output(wrapped_key, wrapped_key_len, output);
2✔
50
   });
6✔
51
#else
52
   BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
53
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
54
#endif
55
}
56

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

74
      auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
2✔
75
      bc->set_key(kek, kek_len);
2✔
76

77
      Botan::secure_vector<uint8_t> output;
2✔
78

79
      if(padded == 0) {
2✔
80
         output = Botan::nist_key_unwrap(wrapped_key, wrapped_key_len, *bc);
4✔
81
      } else {
82
         output = Botan::nist_key_unwrap_padded(wrapped_key, wrapped_key_len, *bc);
×
83
      }
84

85
      return write_vec_output(key, key_len, output);
2✔
86
   });
6✔
87
#else
88
   BOTAN_UNUSED(cipher_algo, padded, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
89
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
90
#endif
91
}
92

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

101
   return botan_nist_kw_enc(cipher_name.c_str(), 0, key, key_len, kek, kek_len, wrapped_key, wrapped_key_len);
1✔
102
}
1✔
103

104
int botan_key_unwrap3394(const uint8_t wrapped_key[],
1✔
105
                         size_t wrapped_key_len,
106
                         const uint8_t kek[],
107
                         size_t kek_len,
108
                         uint8_t key[],
109
                         size_t* key_len) {
110
   const std::string cipher_name = "AES-" + std::to_string(8 * kek_len);
2✔
111

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