blob: 2e597f1af512c3ef4cc485341486a8c1d028f1b7 [file] [log] [blame]
Joel Galensonca0efb12020-10-01 14:32:30 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __CRYPTO_H__
18#define __CRYPTO_H__
19
20#include <stdbool.h>
21#include <stdint.h>
22#include <stddef.h>
23
24extern "C" {
Janis Danisevskis9d90b812020-11-25 21:02:11 -080025 bool randomBytes(uint8_t* out, size_t len);
Joel Galensonca0efb12020-10-01 14:32:30 -070026 bool AES_gcm_encrypt(const uint8_t* in, uint8_t* out, size_t len,
27 const uint8_t* key, size_t key_size, const uint8_t* iv, uint8_t* tag);
28 bool AES_gcm_decrypt(const uint8_t* in, uint8_t* out, size_t len,
29 const uint8_t* key, size_t key_size, const uint8_t* iv,
30 const uint8_t* tag);
31
32 // Copied from system/security/keystore/keymaster_enforcement.h.
33 typedef uint64_t km_id_t;
34
35 bool CreateKeyId(const uint8_t* key_blob, size_t len, km_id_t* out_id);
36
37 void generateKeyFromPassword(uint8_t* key, size_t key_len, const char* pw,
Janis Danisevskis9d90b812020-11-25 21:02:11 -080038 size_t pw_len, const uint8_t* salt);
Joel Galensonca0efb12020-10-01 14:32:30 -070039}
40
41#endif // __CRYPTO_H__