blob: 8efbe687fb22299f4f1438cb6420ee08f200c2e1 [file] [log] [blame]
dianlujitao47d41f62019-10-06 12:04:33 +08001/*
2 * Copyright (C) 2019 The LineageOS 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#include "CryptfsHwUtils.h"
18
19#include <algorithm>
20#include <cstring>
21
22namespace vendor {
23namespace qti {
24namespace hardware {
25namespace cryptfshw {
26namespace V1_0 {
27namespace implementation {
28
29void* secure_memset(void* v, int c, size_t n) {
30 auto p = reinterpret_cast<volatile unsigned char*>(v);
31 while (n--) *p++ = c;
32 return v;
33}
34
35void GetTmpPasswd(const char* passwd, unsigned char* tmp_passwd, size_t buf_len) {
36 secure_memset(tmp_passwd, 0, buf_len);
37 if (passwd) {
38 size_t passwd_len = strnlen(passwd, buf_len);
39 memcpy(tmp_passwd, passwd, passwd_len);
40 }
41}
42
43} // namespace implementation
44} // namespace V1_0
45} // namespace cryptfshw
46} // namespace hardware
47} // namespace qti
48} // namespace vendor