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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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
      }
34
      auto bc = Botan::BlockCipher::create_or_throw(cipher_algo);
2✔
35
      bc->set_key(kek, kek_len);
2✔
36

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

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

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

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

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

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

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

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

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

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

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

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