[23503] | 1 | /* $Id: openssl-sha1.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * IPRT - SHA-1 hash functions.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
[23503] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[23503] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[23503] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[23503] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[23503] | 35 | */
|
---|
| 36 |
|
---|
| 37 |
|
---|
[57358] | 38 | /*********************************************************************************************************************************
|
---|
| 39 | * Header Files *
|
---|
| 40 | *********************************************************************************************************************************/
|
---|
[23503] | 41 | #include "internal/iprt.h"
|
---|
| 42 |
|
---|
[85121] | 43 | #include "internal/openssl-pre.h"
|
---|
[23503] | 44 | #include <openssl/sha.h>
|
---|
[85121] | 45 | #include "internal/openssl-post.h"
|
---|
[23503] | 46 |
|
---|
| 47 | #define RT_SHA1_PRIVATE_CONTEXT
|
---|
| 48 | #include <iprt/sha.h>
|
---|
| 49 |
|
---|
| 50 | #include <iprt/assert.h>
|
---|
[57572] | 51 | #include <iprt/string.h>
|
---|
[23503] | 52 |
|
---|
[57572] | 53 |
|
---|
[23503] | 54 | AssertCompile(RT_SIZEOFMEMB(RTSHA1CONTEXT, abPadding) >= RT_SIZEOFMEMB(RTSHA1CONTEXT, Private));
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | RTDECL(void) RTSha1(const void *pvBuf, size_t cbBuf, uint8_t pabDigest[RTSHA1_HASH_SIZE])
|
---|
| 58 | {
|
---|
| 59 | RTSHA1CONTEXT Ctx;
|
---|
| 60 | RTSha1Init(&Ctx);
|
---|
| 61 | RTSha1Update(&Ctx, pvBuf, cbBuf);
|
---|
| 62 | RTSha1Final(&Ctx, pabDigest);
|
---|
| 63 | }
|
---|
| 64 | RT_EXPORT_SYMBOL(RTSha1);
|
---|
| 65 |
|
---|
| 66 |
|
---|
[57572] | 67 | RTDECL(bool) RTSha1Check(const void *pvBuf, size_t cbBuf, uint8_t const pabDigest[RTSHA1_HASH_SIZE])
|
---|
| 68 | {
|
---|
| 69 | RTSHA1CONTEXT Ctx;
|
---|
| 70 | RTSha1Init(&Ctx);
|
---|
| 71 | RTSha1Update(&Ctx, pvBuf, cbBuf);
|
---|
| 72 | uint8_t abActualDigest[RTSHA1_HASH_SIZE];
|
---|
| 73 | RTSha1Final(&Ctx, abActualDigest);
|
---|
| 74 | bool fRet = memcmp(pabDigest, abActualDigest, RTSHA1_HASH_SIZE) == 0;
|
---|
| 75 | RT_ZERO(abActualDigest);
|
---|
| 76 | return fRet;
|
---|
| 77 | }
|
---|
| 78 | RT_EXPORT_SYMBOL(RTSha1Check);
|
---|
| 79 |
|
---|
| 80 |
|
---|
[23503] | 81 | RTDECL(void) RTSha1Init(PRTSHA1CONTEXT pCtx)
|
---|
| 82 | {
|
---|
| 83 | SHA1_Init(&pCtx->Private);
|
---|
| 84 | }
|
---|
| 85 | RT_EXPORT_SYMBOL(RTSha1Init);
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | RTDECL(void) RTSha1Update(PRTSHA1CONTEXT pCtx, const void *pvBuf, size_t cbBuf)
|
---|
| 89 | {
|
---|
| 90 | SHA1_Update(&pCtx->Private, pvBuf, cbBuf);
|
---|
| 91 | }
|
---|
| 92 | RT_EXPORT_SYMBOL(RTSha1Update);
|
---|
| 93 |
|
---|
| 94 |
|
---|
[57572] | 95 | RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE])
|
---|
[23503] | 96 | {
|
---|
| 97 | SHA1_Final((unsigned char *)&pabDigest[0], &pCtx->Private);
|
---|
| 98 | }
|
---|
| 99 | RT_EXPORT_SYMBOL(RTSha1Final);
|
---|
| 100 |
|
---|