dianlujitao | 47d41f6 | 2019-10-06 12:04:33 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | namespace vendor { |
| 23 | namespace qti { |
| 24 | namespace hardware { |
| 25 | namespace cryptfshw { |
| 26 | namespace V1_0 { |
| 27 | namespace implementation { |
| 28 | |
| 29 | void* 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 | |
| 35 | void 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 |