15acaca2fSWilliam A. Kennington III /* 25acaca2fSWilliam A. Kennington III * Copyright 2021 Google LLC 35acaca2fSWilliam A. Kennington III * 45acaca2fSWilliam A. Kennington III * Licensed under the Apache License, Version 2.0 (the "License"); 55acaca2fSWilliam A. Kennington III * you may not use this file except in compliance with the License. 65acaca2fSWilliam A. Kennington III * You may obtain a copy of the License at 75acaca2fSWilliam A. Kennington III * 85acaca2fSWilliam A. Kennington III * http://www.apache.org/licenses/LICENSE-2.0 95acaca2fSWilliam A. Kennington III * 105acaca2fSWilliam A. Kennington III * Unless required by applicable law or agreed to in writing, software 115acaca2fSWilliam A. Kennington III * distributed under the License is distributed on an "AS IS" BASIS, 125acaca2fSWilliam A. Kennington III * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135acaca2fSWilliam A. Kennington III * See the License for the specific language governing permissions and 145acaca2fSWilliam A. Kennington III * limitations under the License. 155acaca2fSWilliam A. Kennington III */ 16*dca92e47SWilly Tu 175acaca2fSWilliam A. Kennington III #ifndef PLATFORMS_HAVEN_LIBCR51SIGN_LIBCR51SIGN_SUPPORT_H_ 185acaca2fSWilliam A. Kennington III #define PLATFORMS_HAVEN_LIBCR51SIGN_LIBCR51SIGN_SUPPORT_H_ 195acaca2fSWilliam A. Kennington III 20*dca92e47SWilly Tu #include <libcr51sign/libcr51sign.h> 215acaca2fSWilliam A. Kennington III #include <openssl/sha.h> 225acaca2fSWilliam A. Kennington III 235acaca2fSWilliam A. Kennington III #ifdef __cplusplus 245acaca2fSWilliam A. Kennington III extern "C" 255acaca2fSWilliam A. Kennington III { 265acaca2fSWilliam A. Kennington III #endif 275acaca2fSWilliam A. Kennington III 285acaca2fSWilliam A. Kennington III struct hash_ctx 295acaca2fSWilliam A. Kennington III { 305acaca2fSWilliam A. Kennington III enum hash_type hash_type; 315acaca2fSWilliam A. Kennington III union 325acaca2fSWilliam A. Kennington III { 335acaca2fSWilliam A. Kennington III SHA256_CTX sha256_ctx; 345acaca2fSWilliam A. Kennington III SHA512_CTX sha512_ctx; 355acaca2fSWilliam A. Kennington III }; 365acaca2fSWilliam A. Kennington III }; 375acaca2fSWilliam A. Kennington III 385acaca2fSWilliam A. Kennington III // @func hash_init get ready to compute a hash 395acaca2fSWilliam A. Kennington III // 405acaca2fSWilliam A. Kennington III // @param[in] ctx - context struct 415acaca2fSWilliam A. Kennington III // @param[in] hash_type - type of hash function to use 425acaca2fSWilliam A. Kennington III // 435acaca2fSWilliam A. Kennington III // @return nonzero on error, zero on success 445acaca2fSWilliam A. Kennington III 455acaca2fSWilliam A. Kennington III int hash_init(const void* ctx, enum hash_type type); 465acaca2fSWilliam A. Kennington III 475acaca2fSWilliam A. Kennington III // @func hash_update add data to the hash 485acaca2fSWilliam A. Kennington III // 495acaca2fSWilliam A. Kennington III // @param[in] ctx - context struct 505acaca2fSWilliam A. Kennington III // @param[in] buf - data to add to hash 515acaca2fSWilliam A. Kennington III // @param[in] count - number of bytes of data to add 525acaca2fSWilliam A. Kennington III // 535acaca2fSWilliam A. Kennington III // @return nonzero on error, zero on success 545acaca2fSWilliam A. Kennington III 555acaca2fSWilliam A. Kennington III int hash_update(void* ctx, const uint8_t* data, size_t size); 565acaca2fSWilliam A. Kennington III 575acaca2fSWilliam A. Kennington III // @func hash_final finish hash calculation 585acaca2fSWilliam A. Kennington III // 595acaca2fSWilliam A. Kennington III // @param[in] ctx - context struct 605acaca2fSWilliam A. Kennington III // @param[out] hash - buffer to write hash to (guaranteed to be big enough) 615acaca2fSWilliam A. Kennington III // 625acaca2fSWilliam A. Kennington III // @return nonzero on error, zero on success 635acaca2fSWilliam A. Kennington III 645acaca2fSWilliam A. Kennington III int hash_final(void* ctx, uint8_t* hash); 655acaca2fSWilliam A. Kennington III 665acaca2fSWilliam A. Kennington III // @func verify check that the signature is valid for given hashed data 675acaca2fSWilliam A. Kennington III // 685acaca2fSWilliam A. Kennington III // @param[in] ctx - context struct 695acaca2fSWilliam A. Kennington III // @param[in] scheme - type of signature, hash, etc. 705acaca2fSWilliam A. Kennington III // @param[in] sig - signature blob 715acaca2fSWilliam A. Kennington III // @param[in] sig_len - length of signature in bytes 725acaca2fSWilliam A. Kennington III // @param[in] data - pre-hashed data to verify 735acaca2fSWilliam A. Kennington III // @param[in] data_len - length of hashed data in bytes 745acaca2fSWilliam A. Kennington III // 755acaca2fSWilliam A. Kennington III // @return nonzero on error, zero on success 765acaca2fSWilliam A. Kennington III 775acaca2fSWilliam A. Kennington III int verify_signature(const void* ctx, enum signature_scheme sig_scheme, 786084957fSPatrick Williams const uint8_t* sig, size_t sig_len, const uint8_t* data, 796084957fSPatrick Williams size_t data_len); 805acaca2fSWilliam A. Kennington III 815acaca2fSWilliam A. Kennington III #ifdef __cplusplus 825acaca2fSWilliam A. Kennington III } // extern "C" 835acaca2fSWilliam A. Kennington III #endif 845acaca2fSWilliam A. Kennington III #endif // PLATFORMS_HAVEN_LIBCR51SIGN_LIBCR51SIGN_SUPPORT_H_ 85