0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/UI/nix-update/crypto-helpers-mac.mm

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1016 B
Plaintext
Raw Normal View History

#include "crypto-helpers.hpp"
#import <Foundation/Foundation.h>
#import <Security/Security.h>
#import <Security/SecKey.h>
bool VerifySignature(const uint8_t *pubKey, const size_t pubKeyLen,
const uint8_t *buf, const size_t len, const uint8_t *sig,
const size_t sigLen)
{
NSData *pubKeyData = [NSData dataWithBytes:pubKey length:pubKeyLen];
CFArrayRef items = nullptr;
OSStatus res = SecItemImport((CFDataRef)pubKeyData, nullptr, nullptr,
nullptr, (SecItemImportExportFlags)0,
nullptr, nullptr, &items);
if (res != errSecSuccess)
return false;
SecKeyRef pubKeyRef = (SecKeyRef)CFArrayGetValueAtIndex(items, 0);
NSData *signedData = [NSData dataWithBytes:buf length:len];
NSData *signature = [NSData dataWithBytes:sig length:sigLen];
CFErrorRef errRef;
bool result = SecKeyVerifySignature(
pubKeyRef, kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA512,
(__bridge CFDataRef)signedData, (__bridge CFDataRef)signature,
&errRef);
CFRelease(items);
return result;
};