mirror of
https://gitlab.freedesktop.org/xorg/xserver.git
synced 2025-12-20 18:40:02 +01:00
os: Use EVP APIs when building with OpenSSL 3
Avoids deprecation warnings for old SHA1 APIs in OpenSSL 3.0 and later Closes: #1845 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2066>
This commit is contained in:
parent
7013984b5f
commit
3ec5f6bcc3
2 changed files with 53 additions and 3 deletions
2
COPYING
2
COPYING
|
|
@ -16,7 +16,7 @@ Copyright © 2006 Nokia Corporation
|
||||||
Copyright © 2006-2008 Peter Hutterer
|
Copyright © 2006-2008 Peter Hutterer
|
||||||
Copyright © 2006 Adam Jackson
|
Copyright © 2006 Adam Jackson
|
||||||
Copyright © 2009-2010 NVIDIA Corporation
|
Copyright © 2009-2010 NVIDIA Corporation
|
||||||
Copyright © 1987, 2003-2006, 2008-2010 Oracle and/or its affiliates.
|
Copyright © 1987, 2003-2006, 2008-2010, 2025 Oracle and/or its affiliates.
|
||||||
Copyright © 1999 Keith Packard
|
Copyright © 1999 Keith Packard
|
||||||
Copyright © 2007-2009 Red Hat, Inc.
|
Copyright © 2007-2009 Red Hat, Inc.
|
||||||
Copyright © 2005-2008 Daniel Stone
|
Copyright © 2005-2008 Daniel Stone
|
||||||
|
|
|
||||||
52
os/xsha1.c
52
os/xsha1.c
|
|
@ -1,7 +1,10 @@
|
||||||
/* Copyright © 2007 Carl Worth
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright © 2007 Carl Worth
|
||||||
* Copyright © 2009 Jeremy Huddleston, Julien Cristau, and Matthieu Herrb
|
* Copyright © 2009 Jeremy Huddleston, Julien Cristau, and Matthieu Herrb
|
||||||
* Copyright © 2009-2010 Mikhail Gusarov
|
* Copyright © 2009-2010 Mikhail Gusarov
|
||||||
* Copyright © 2012 Yaakov Selkowitz and Keith Packard
|
* Copyright © 2012 Yaakov Selkowitz and Keith Packard
|
||||||
|
* Copyright (c) 2025, Oracle and/or its affiliates.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
|
@ -254,13 +257,43 @@ x_sha1_final(void *ctx, unsigned char result[20])
|
||||||
|
|
||||||
#else /* Use OpenSSL's libcrypto */
|
#else /* Use OpenSSL's libcrypto */
|
||||||
|
|
||||||
|
#include <openssl/opensslv.h>
|
||||||
|
#if OPENSSL_VERSION_MAJOR >= 3
|
||||||
|
#define USE_EVP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVP
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
#else
|
||||||
#include <stddef.h> /* buggy openssl/sha.h wants size_t */
|
#include <stddef.h> /* buggy openssl/sha.h wants size_t */
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVP
|
||||||
|
static EVP_MD *sha1 = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
void *
|
void *
|
||||||
x_sha1_init(void)
|
x_sha1_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
#ifdef USE_EVP
|
||||||
|
EVP_MD_CTX *ctx;
|
||||||
|
|
||||||
|
if (sha1 == NULL) {
|
||||||
|
sha1 = EVP_MD_fetch(NULL, "SHA1", NULL);
|
||||||
|
if (sha1 == NULL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ctx = EVP_MD_CTX_new();
|
||||||
|
if (ctx == NULL)
|
||||||
|
return NULL;
|
||||||
|
ret = EVP_DigestInit_ex2(ctx, sha1, NULL);
|
||||||
|
if (!ret) {
|
||||||
|
EVP_MD_CTX_free(ctx);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
SHA_CTX *ctx = malloc(sizeof(*ctx));
|
SHA_CTX *ctx = malloc(sizeof(*ctx));
|
||||||
|
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
|
|
@ -270,6 +303,7 @@ x_sha1_init(void)
|
||||||
free(ctx);
|
free(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,11 +311,19 @@ int
|
||||||
x_sha1_update(void *ctx, void *data, int size)
|
x_sha1_update(void *ctx, void *data, int size)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
#ifdef USE_EVP
|
||||||
|
EVP_MD_CTX *sha_ctx = ctx;
|
||||||
|
|
||||||
|
ret = EVP_DigestUpdate(sha_ctx, data, size);
|
||||||
|
if (!ret)
|
||||||
|
EVP_MD_CTX_free(sha_ctx);
|
||||||
|
#else
|
||||||
SHA_CTX *sha_ctx = ctx;
|
SHA_CTX *sha_ctx = ctx;
|
||||||
|
|
||||||
ret = SHA1_Update(sha_ctx, data, size);
|
ret = SHA1_Update(sha_ctx, data, size);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
free(sha_ctx);
|
free(sha_ctx);
|
||||||
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -289,10 +331,18 @@ int
|
||||||
x_sha1_final(void *ctx, unsigned char result[20])
|
x_sha1_final(void *ctx, unsigned char result[20])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
#ifdef USE_EVP
|
||||||
|
EVP_MD_CTX *sha_ctx = ctx;
|
||||||
|
unsigned int result_len = 20; /* size of result buffer */
|
||||||
|
|
||||||
|
ret = EVP_DigestFinal_ex(sha_ctx, result, &result_len);
|
||||||
|
EVP_MD_CTX_free(sha_ctx);
|
||||||
|
#else
|
||||||
SHA_CTX *sha_ctx = ctx;
|
SHA_CTX *sha_ctx = ctx;
|
||||||
|
|
||||||
ret = SHA1_Final(result, sha_ctx);
|
ret = SHA1_Final(result, sha_ctx);
|
||||||
free(sha_ctx);
|
free(sha_ctx);
|
||||||
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue