master
1const std = @import("std");
2const uefi = std.os.uefi;
3const Guid = uefi.Guid;
4const Status = uefi.Status;
5const cc = uefi.cc;
6const Error = Status.Error;
7
8/// Random Number Generator protocol
9pub const Rng = extern struct {
10 _get_info: *const fn (*const Rng, *usize, [*]align(8) Guid) callconv(cc) Status,
11 _get_rng: *const fn (*const Rng, ?*align(8) const Guid, usize, [*]u8) callconv(cc) Status,
12
13 pub const GetInfoError = uefi.UnexpectedError || error{
14 Unsupported,
15 DeviceError,
16 BufferTooSmall,
17 };
18 pub const GetRNGError = uefi.UnexpectedError || error{
19 Unsupported,
20 DeviceError,
21 NotReady,
22 InvalidParameter,
23 };
24
25 /// Returns information about the random number generation implementation.
26 pub fn getInfo(self: *const Rng, list: []align(8) Guid) GetInfoError![]align(8) Guid {
27 var len: usize = list.len;
28 switch (self._get_info(self, &len, list.ptr)) {
29 .success => return list[0..len],
30 .unsupported => return Error.Unsupported,
31 .device_error => return Error.DeviceError,
32 .buffer_too_small => return Error.BufferTooSmall,
33 else => |status| return uefi.unexpectedStatus(status),
34 }
35 }
36
37 /// Produces and returns an RNG value using either the default or specified RNG algorithm.
38 pub fn getRNG(self: *const Rng, algo: ?*align(8) const Guid, value: []u8) GetRNGError!void {
39 switch (self._get_rng(self, algo, value.len, value.ptr)) {
40 .success => {},
41 .unsupported => return Error.Unsupported,
42 .device_error => return Error.DeviceError,
43 .not_ready => return Error.NotReady,
44 .invalid_parameter => return Error.InvalidParameter,
45 else => |status| return uefi.unexpectedStatus(status),
46 }
47 }
48
49 pub const guid align(8) = Guid{
50 .time_low = 0x3152bca5,
51 .time_mid = 0xeade,
52 .time_high_and_version = 0x433d,
53 .clock_seq_high_and_reserved = 0x86,
54 .clock_seq_low = 0x2e,
55 .node = [_]u8{ 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 },
56 };
57 pub const algorithm_sp800_90_hash_256 align(8) = Guid{
58 .time_low = 0xa7af67cb,
59 .time_mid = 0x603b,
60 .time_high_and_version = 0x4d42,
61 .clock_seq_high_and_reserved = 0xba,
62 .clock_seq_low = 0x21,
63 .node = [_]u8{ 0x70, 0xbf, 0xb6, 0x29, 0x3f, 0x96 },
64 };
65 pub const algorithm_sp800_90_hmac_256 align(8) = Guid{
66 .time_low = 0xc5149b43,
67 .time_mid = 0xae85,
68 .time_high_and_version = 0x4f53,
69 .clock_seq_high_and_reserved = 0x99,
70 .clock_seq_low = 0x82,
71 .node = [_]u8{ 0xb9, 0x43, 0x35, 0xd3, 0xa9, 0xe7 },
72 };
73 pub const algorithm_sp800_90_ctr_256 align(8) = Guid{
74 .time_low = 0x44f0de6e,
75 .time_mid = 0x4d8c,
76 .time_high_and_version = 0x4045,
77 .clock_seq_high_and_reserved = 0xa8,
78 .clock_seq_low = 0xc7,
79 .node = [_]u8{ 0x4d, 0xd1, 0x68, 0x85, 0x6b, 0x9e },
80 };
81 pub const algorithm_x9_31_3des align(8) = Guid{
82 .time_low = 0x63c4785a,
83 .time_mid = 0xca34,
84 .time_high_and_version = 0x4012,
85 .clock_seq_high_and_reserved = 0xa3,
86 .clock_seq_low = 0xc8,
87 .node = [_]u8{ 0x0b, 0x6a, 0x32, 0x4f, 0x55, 0x46 },
88 };
89 pub const algorithm_x9_31_aes align(8) = Guid{
90 .time_low = 0xacd03321,
91 .time_mid = 0x777e,
92 .time_high_and_version = 0x4d3d,
93 .clock_seq_high_and_reserved = 0xb1,
94 .clock_seq_low = 0xc8,
95 .node = [_]u8{ 0x20, 0xcf, 0xd8, 0x88, 0x20, 0xc9 },
96 };
97 pub const algorithm_raw align(8) = Guid{
98 .time_low = 0xe43176d7,
99 .time_mid = 0xb6e8,
100 .time_high_and_version = 0x4827,
101 .clock_seq_high_and_reserved = 0xb7,
102 .clock_seq_low = 0x84,
103 .node = [_]u8{ 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 },
104 };
105};