VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/checksum/openssl-sha1.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1/* $Id: openssl-sha1.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT - SHA-1 hash functions.
4 */
5
6/*
7 * Copyright (C) 2009-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
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 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
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
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.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "internal/iprt.h"
42
43#include "internal/openssl-pre.h"
44#include <openssl/sha.h>
45#include "internal/openssl-post.h"
46
47#define RT_SHA1_PRIVATE_CONTEXT
48#include <iprt/sha.h>
49
50#include <iprt/assert.h>
51#include <iprt/string.h>
52
53
54AssertCompile(RT_SIZEOFMEMB(RTSHA1CONTEXT, abPadding) >= RT_SIZEOFMEMB(RTSHA1CONTEXT, Private));
55
56
57RTDECL(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}
64RT_EXPORT_SYMBOL(RTSha1);
65
66
67RTDECL(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}
78RT_EXPORT_SYMBOL(RTSha1Check);
79
80
81RTDECL(void) RTSha1Init(PRTSHA1CONTEXT pCtx)
82{
83 SHA1_Init(&pCtx->Private);
84}
85RT_EXPORT_SYMBOL(RTSha1Init);
86
87
88RTDECL(void) RTSha1Update(PRTSHA1CONTEXT pCtx, const void *pvBuf, size_t cbBuf)
89{
90 SHA1_Update(&pCtx->Private, pvBuf, cbBuf);
91}
92RT_EXPORT_SYMBOL(RTSha1Update);
93
94
95RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE])
96{
97 SHA1_Final((unsigned char *)&pabDigest[0], &pCtx->Private);
98}
99RT_EXPORT_SYMBOL(RTSha1Final);
100
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette