bigbiff bigbiff | 56cf564 | 2016-08-19 17:43:45 -0400 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2012 to 2017 TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include <vector> |
| 20 | #include <string> |
| 21 | #include <sstream> |
| 22 | #include <string> |
| 23 | #include <openssl/sha.h> |
| 24 | #include "twrpDigest.hpp" |
| 25 | #include "twrpSHA.hpp" |
| 26 | |
| 27 | twrpSHA256::twrpSHA256() { |
| 28 | twrpSHA256::init(); |
| 29 | } |
| 30 | |
| 31 | void twrpSHA256::init(void) { |
| 32 | SHA256_Init(&sha256_ctx); |
| 33 | } |
| 34 | |
| 35 | void twrpSHA256::update(const unsigned char* stream, size_t len) { |
| 36 | SHA256_Update(&sha256_ctx, stream, len); |
| 37 | } |
| 38 | |
| 39 | void twrpSHA256::finalize(void) { |
| 40 | SHA256_Final(sha256_store, &sha256_ctx); |
| 41 | } |
| 42 | |
| 43 | std::string twrpSHA256::return_digest_string(void) { |
| 44 | twrpSHA256::finalize(); |
| 45 | std::string digest_str = twrpDigest::hexify(sha256_store, SHA256_DIGEST_LENGTH); |
| 46 | return digest_str; |
| 47 | } |
| 48 | |
| 49 | twrpSHA512::twrpSHA512() { |
| 50 | twrpSHA512::init(); |
| 51 | } |
| 52 | |
| 53 | void twrpSHA512::init(void) { |
| 54 | SHA512_Init(&sha512_ctx); |
| 55 | } |
| 56 | |
| 57 | void twrpSHA512::update(const unsigned char* stream, size_t len) { |
| 58 | SHA512_Update(&sha512_ctx, stream, len); |
| 59 | } |
| 60 | |
| 61 | void twrpSHA512::finalize(void) { |
| 62 | SHA512_Final(sha512_store, &sha512_ctx); |
| 63 | } |
| 64 | |
| 65 | std::string twrpSHA512::return_digest_string(void) { |
| 66 | twrpSHA512::finalize(); |
| 67 | std::string digest_str = twrpDigest::hexify(sha512_store, SHA512_DIGEST_LENGTH); |
| 68 | return digest_str; |
| 69 | } |