mirror of
https://github.com/apple/swift-crypto
synced 2026-11-28 05:04:21 +00:00
Add SHA-512/256 digest implementation via BoringSSL ### Checklist - [x] I've run tests to see all new and existing tests pass - [x] I've followed the code style of the rest of the project - [x] I've read the [Contribution Guidelines](CONTRIBUTING.md) - [x] I've updated the documentation if necessary #### If you've made changes to `gyb` files - [N/A] I've run `.script/generate_boilerplate_files_with_gyb` and included updated generated files in a commit of this pull request ### Motivation: Neither CryptoKit nor swift-crypto currently explore the SHA-512/256 hashing function. SHA-512/256 provides the same 256-bit security level as SHA-256 but can be significantly faster on 64-bit platforms because it uses the SHA-512 internal structure, which operates on 64-bit words. ### Modifications: We modified CryptoExtras to include support using the BoringSSL implementation. ### Result: Swift ecosystem supports SHA-512/256. --------- Co-authored-by: Cory Benfield <lukasa@apple.com>
30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftCrypto open source project
|
|
//
|
|
// Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#if !canImport(Darwin)
|
|
@_implementationOnly import CCryptoBoringSSL
|
|
|
|
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
|
typealias errno_t = CInt
|
|
|
|
// This is a Swift wrapper for the libc function that does not exist on Linux. We shim it via a call to OPENSSL_cleanse.
|
|
// We have the same syntax, but mostly ignore it.
|
|
@discardableResult
|
|
func memset_s(_ s: UnsafeMutableRawPointer!, _ smax: Int, _ byte: CInt, _ n: Int) -> errno_t {
|
|
assert(smax == n, "memset_s invariant not met")
|
|
assert(byte == 0, "memset_s used to not zero anything")
|
|
CCryptoBoringSSL_OPENSSL_cleanse(s, smax)
|
|
return 0
|
|
}
|
|
#endif
|