-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.16.0-dev.1234+74900e938
Steps to Reproduce and Observed Behavior
Running:
#!/bin/bash
set -eu
wget 'https://ziglang.org/builds/zig-x86_64-linux-0.16.0-dev.1234+74900e938.tar.xz'
tar Jxf zig-x86_64-linux-0.16.0-dev.1234+74900e938.tar.xz
mkdir poc/
cd poc/
cat > poc.zig << 'EOF'
const std = @import("std");
const ecdsa = std.crypto.sign.ecdsa;
export fn zig_poc() callconv(.c) void {
const key = [_]u8{
0x04,
// P-256 generator point
0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
};
if (ecdsa.EcdsaP256Sha256.PublicKey.fromSec1(&key)) |_| {
std.debug.print("OK\n", .{});
} else |_| {
std.debug.print("Fail\n", .{});
}
}
EOF
cat > stub.c << 'EOF'
void zig_poc(void);
int main(void)
{
zig_poc();
return 0;
}
EOF
../zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig build-lib -femit-llvm-bc=poc.bc -fcompiler-rt poc.zig
../zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig cc -O0 -o poc_O0 stub.c poc.bc
../zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig cc -O1 -o poc_O1 stub.c poc.bc
../zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig cc -O2 -o poc_O2 stub.c poc.bc
../zig-x86_64-linux-0.16.0-dev.1234+74900e938/zig cc -O3 -o poc_O3 stub.c poc.bc
echo -n "poc_O0: "; ./poc_O0
echo -n "poc_O1: "; ./poc_O1
echo -n "poc_O2: "; ./poc_O2
echo -n "poc_O3: "; ./poc_O3Prints:
poc_O0: OK
poc_O1: Fail
poc_O2: Fail
poc_O3: Fail
Expected Behavior
Should print:
poc_O0: OK
poc_O1: OK
poc_O2: OK
poc_O3: OK
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior