28
28
#include " openssl/cmac.h"
29
29
#include " openssl/evp.h"
30
30
#include " tink/internal/aes_util.h"
31
+ #include " tink/internal/call_with_core_dump_protection.h"
31
32
#include " tink/internal/fips_utils.h"
32
33
#include " tink/internal/ssl_unique_ptr.h"
33
34
#include " tink/internal/util.h"
@@ -84,16 +85,21 @@ util::StatusOr<std::string> AesCmacBoringSsl::ComputeMac(
84
85
return cipher.status ();
85
86
}
86
87
size_t len = 0 ;
87
- const uint8_t * key_ptr = reinterpret_cast <const uint8_t *>(&key_[0 ]);
88
88
const uint8_t * data_ptr = reinterpret_cast <const uint8_t *>(data.data ());
89
89
uint8_t * result_ptr = reinterpret_cast <uint8_t *>(&result[0 ]);
90
- if (CMAC_Init (context.get (), key_ptr, key_.size (), *cipher, nullptr ) <= 0 ||
91
- CMAC_Update (context.get (), data_ptr, data.size ()) <= 0 ||
92
- CMAC_Final (context.get (), result_ptr, &len) == 0 ) {
90
+ bool res = internal::CallWithCoreDumpProtection ([&]() {
91
+ if (CMAC_Init (context.get (), key_.data (), key_.size (), *cipher, nullptr ) <=
92
+ 0 ||
93
+ CMAC_Update (context.get (), data_ptr, data.size ()) <= 0 ||
94
+ CMAC_Final (context.get (), result_ptr, &len) == 0 ) {
95
+ return false ;
96
+ }
97
+ result.resize (tag_size_);
98
+ return true ;
99
+ });
100
+ if (!res) {
93
101
return util::Status (absl::StatusCode::kInternal , " Failed to compute CMAC" );
94
102
}
95
-
96
- result.resize (tag_size_);
97
103
return result;
98
104
}
99
105
@@ -104,13 +110,15 @@ util::Status AesCmacBoringSsl::VerifyMac(absl::string_view mac,
104
110
" Incorrect tag size: expected %d, found %d" , tag_size_,
105
111
mac.size ());
106
112
}
107
- util::StatusOr<std::string> computed_mac = ComputeMac (data);
108
- if (!computed_mac.ok ()) return computed_mac.status ();
109
- if (CRYPTO_memcmp (computed_mac->data (), mac.data (), tag_size_) != 0 ) {
110
- return util::Status (absl::StatusCode::kInvalidArgument ,
111
- " CMAC verification failed" );
112
- }
113
- return util::OkStatus ();
113
+ return internal::CallWithCoreDumpProtection ([&]() {
114
+ util::StatusOr<std::string> computed_mac = ComputeMac (data);
115
+ if (!computed_mac.ok ()) return computed_mac.status ();
116
+ if (CRYPTO_memcmp (computed_mac->data (), mac.data (), tag_size_) != 0 ) {
117
+ return util::Status (absl::StatusCode::kInvalidArgument ,
118
+ " CMAC verification failed" );
119
+ }
120
+ return util::OkStatus ();
121
+ });
114
122
}
115
123
116
124
} // namespace subtle
0 commit comments