1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
#!/usr/bin/perl
#
# Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use strict;
use warnings;
my %internal = (
asn1 => [qw(
ASN1_ENCODING
ASN1_STRING_FLAG_CONT
ASN1_STRING_FLAG_MSTRING ASN1_STRING_FLAG_NDEF
CHARTYPE_FIRST_ESC_2253 CHARTYPE_LAST_ESC_2253 CHARTYPE_PRINTABLESTRING
)],
bn => [qw(
BN_BITS BN_BITS4 BN_BYTES
BN_DEC_CONV BN_DEC_FMT1 BN_DEC_FMT2 BN_DEC_NUM BN_LLONG BN_LONG
BN_MASK2 BN_MASK2h BN_MASK2h1 BN_MASK2l
BN_TBIT BN_ULLONG
)],
evp => [qw(
EVP_MD_CTRL_ALG_CTRL
EVP_MD_CTX_FLAG_CLEANED EVP_MD_CTX_FLAG_REUSE
)],
objects => [qw(
OBJ_bsearch_ OBJ_bsearch_ex_
)],
x509_vfy => [qw(
X509_VERIFY_PARAM_ID
)]
);
my %obsolete = (
asn1 => [qw(
ASN1_dup ASN1_d2i_bio ASN1_d2i_bio_of ASN1_d2i_fp ASN1_d2i_fp_of
ASN1_i2d_bio ASN1_i2d_bio_of ASN1_i2d_bio_of_const
ASN1_i2d_fp ASN1_i2d_fp_of ASN1_i2d_fp_of_const
ASN1_LONG_UNDEF
BIT_STRING_BITNAME
V_ASN1_PRIMATIVE_TAG
X509_algor_st
)],
bio => [qw(
asn1_ps_func
BIO_C_GET_PROXY_PARAM BIO_C_GET_SOCKS
BIO_C_SET_PROXY_PARAM BIO_C_SET_SOCKS
BIO_get_no_connect_return BIO_get_proxies
BIO_get_proxy_header BIO_get_url
BIO_set_filter_bio BIO_set_no_connect_return BIO_set_proxies
BIO_set_proxy_cb BIO_set_proxy_header BIO_set_url
)],
bn => [qw(
BN_HEX_FMT1 BN_HEX_FMT2 BN_MASK
)],
evp => [qw(
EVP_MD_CTRL_DIGALGID
EVP_MD_CTX_FLAG_NON_FIPS_ALLOW EVP_MD_CTX_FLAG_PAD_MASK
EVP_MD_CTX_FLAG_PAD_PKCS1 EVP_MD_CTX_FLAG_PAD_PSS
)],
);
my %postponed = (
asn1 => [qw(
ASN1_ITEM_EXP ASN1_ITEM_ptr ASN1_ITEM_ref ASN1_ITEM_rptr
ASN1_TEMPLATE ASN1_TLC
CHECKED_D2I_OF CHECKED_I2D_OF CHECKED_NEW_OF
CHECKED_PPTR_OF CHECKED_PTR_OF
DECLARE_ASN1_ALLOC_FUNCTIONS DECLARE_ASN1_ALLOC_FUNCTIONS_name
DECLARE_ASN1_ENCODE_FUNCTIONS DECLARE_ASN1_ENCODE_FUNCTIONS_const
DECLARE_ASN1_FUNCTIONS DECLARE_ASN1_FUNCTIONS_const
DECLARE_ASN1_FUNCTIONS_fname DECLARE_ASN1_FUNCTIONS_name
DECLARE_ASN1_ITEM
DECLARE_ASN1_NDEF_FUNCTION
DECLARE_ASN1_PRINT_FUNCTION DECLARE_ASN1_PRINT_FUNCTION_fname
DECLARE_ASN1_SET_OF
D2I_OF
IMPLEMENT_ASN1_SET_OF
I2D_OF I2D_OF_const
TYPEDEF_D2I_OF TYPEDEF_D2I2D_OF TYPEDEF_I2D_OF
)],
x509 => [qw(
NETSCAPE_SPKAC NETSCAPE_SPKI PBEPARAM
)]
);
my $MANW = 'man -M /usr/share/man -w';
my $srcdir = '/usr/src/lib/libcrypto/man';
my $hfile = '/usr/include/openssl';
my $in_cplusplus = 0;
my $in_comment = 0;
my $in_define = 0;
my $in_function = 0;
my $in_struct = 0;
my $in_typedef_struct = 0;
my %expect_undoc = ();
my %found_undoc = ();
my $verbose = 0;
if (defined $ARGV[0] && $ARGV[0] eq '-v') {
$verbose = 1;
shift @ARGV;
}
$#ARGV == 0 or die "usage: $0 [-v] headername";
$hfile .= "/$ARGV[0].h";
open my $in_fh, '<', $hfile or die "$hfile: $!";
$expect_undoc{$_} = 1 foreach @{$internal{$ARGV[0]}};
$expect_undoc{$_} = 1 foreach @{$obsolete{$ARGV[0]}};
$expect_undoc{$_} = 1 foreach @{$postponed{$ARGV[0]}};
while (<$in_fh>) {
try_again:
chomp;
my $line = $_;
# C language comments.
if ($in_comment) {
unless (s/.*?\*\///) {
print "-- $line\n" if $verbose;
next;
}
$in_comment = 0;
}
while (/\/\*/) {
s/\s*\/\*.*?\*\/// and next;
s/\s*\/\*.*// and $in_comment = 1;
}
# End C++ stuff.
if ($in_cplusplus) {
/^#endif$/ and $in_cplusplus = 0;
print "-- $line\n" if $verbose;
next;
}
# End declarations of structs.
if ($in_struct) {
if (/^\s*union\s+{$/) {
print "-s $line\n" if $verbose;
$in_struct++;
next;
}
unless (s/^\s*\}//) {
print "-s $line\n" if $verbose;
next;
}
if (--$in_struct && /^\s+\w+;$/) {
print "-s $line\n" if $verbose;
next;
}
unless ($in_typedef_struct) {
/^\s*;$/ or die "at end of struct: $_";
print "-s $line\n" if $verbose;
next;
}
$in_typedef_struct = 0;
my ($id) = /^\s*(\w+);$/
or die "at end of typedef struct: $_";
unless (system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
print "Vt $line\n" if $verbose;
next;
}
if ($expect_undoc{$id}) {
print "V- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: typedef struct $id";
}
next;
}
# End macro definitions.
if ($in_define) {
/\\$/ or $in_define = 0;
print "-d $line\n" if $verbose;
next;
}
# End function declarations.
if ($in_function) {
/^\s/ or die "function arguments not indented: $_";
/\);$/ and $in_function = 0;
print "-f $line\n" if $verbose;
next;
}
# Begin C++ stuff.
if (/^#ifdef\s+__cplusplus$/) {
$in_cplusplus = 1;
print "-- $line\n" if $verbose;
next;
}
# Uninteresting lines.
if (/^\s*$/ ||
/^DECLARE_STACK_OF\(\w+\)$/ ||
/^TYPEDEF_D2I2D_OF\(\w+\);$/ ||
/^#define __bounded__\(\w+, \w+, \w+\)$/ ||
/^#define HEADER_\w+_H$/ ||
/^#endif$/ ||
/^#else$/ ||
/^extern\s+const\s+ASN1_ITEM\s+\w+_it;$/ ||
/^#\s*include\s/ ||
/^#ifn?def\s/ ||
/^#if !?defined/ ||
/^#undef\s+BN_LLONG$/) {
print "-- $line\n" if $verbose;
next;
}
# Begin declarations of structs.
if (/^(typedef )?(?:struct|enum)(?: \w+)? \{$/) {
$in_struct = 1;
$1 and $in_typedef_struct = 1;
print "-s $line\n" if $verbose;
next;
}
# Handle macros.
if (my ($id) = /^#\s*define\s+(\w+)\s+\S/) {
/\\$/ and $in_define = 1;
if ($id eq 'BN_ULONG' &&
not system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
print "Vt $line\n" if $verbose;
next;
}
unless (system "$MANW -k 'Dv~^$id\$' > /dev/null 2>&1") {
print "Dv $line\n" if $verbose;
next;
}
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
unless (system qw/grep -qR/, '^\.\\\\" .*\<' . $id . '\>',
"$srcdir/") {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /^ASN1_PCTX_FLAGS_\w+$/) {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /^(?:ASN1|BIO|BN|EVP|X509(?:V3)?)_[FR]_\w+$/) {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /^X509_V_ERR_\w+$/) {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /^(?:SN|LN|NID|OBJ)_\w+$/) {
print "D- $line\n" if $verbose;
next;
}
if ($expect_undoc{$id}) {
print "D- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: #define $id";
}
next;
}
if (my ($id) = /^#\s*define\s+(\w+)\(/) {
/\\$/ and $in_define = 1;
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
unless (system qw/grep -qR/, '^\.\\\\" .*\<' . $id . '\>',
"$srcdir/") {
print "F- $line\n" if $verbose;
next;
}
if ($expect_undoc{$id}) {
print "F- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: #define $id()";
}
next;
}
if (my ($id) = /^#\s*define\s+(\w+)$/) {
if ($expect_undoc{$id}) {
print "-- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: #define $id";
}
next;
}
# Handle global variables.
if (my ($id) = /^extern\s+int\s+(\w+);$/) {
unless (system "$MANW -k 'Va~^$id\$' > /dev/null 2>&1") {
print "Va $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: extern int $id";
}
next;
}
# Handle variable type declarations.
if (my ($id) = /^struct\s+(\w+);$/) {
unless (system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
print "Vt $line\n" if $verbose;
next;
}
if ($expect_undoc{$id}) {
print "V- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: struct $id";
}
next;
}
if (my ($id) = /^typedef\s+(?:const\s+)?(?:struct\s+)?\S+\s+(\w+);$/) {
unless (system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
print "Vt $line\n" if $verbose;
next;
}
if ($expect_undoc{$id}) {
print "V- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: typedef $id";
}
next;
}
if (my ($id) =/^typedef\s+\w+(?:\s+\*)?\s+\(\*(\w+)\)\(/) {
/\);$/ or $in_function = 1;
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: function type (*$id)()";
}
next;
}
# Handle function declarations.
if (/^\w+(?:\(\w+\))?(?:\s+\w+)*\s+(?:\(?\*\s*)?(\w+)\(/) {
my $id = $1;
/\);$/ or $in_function = 1;
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
# These functions are still provided by OpenSSL
# and still used by the Python test suite,
# but intentionally undocumented because nothing
# else uses them according to tb@, Dec 3, 2021.
if ($id =~ /NETSCAPE_(?:CERT_SEQUENCE|SPKAC|SPKI)/) {
print "F- $line\n" if $verbose;
next;
}
unless (system qw/grep -qR/, '^\.\\\\" .*\<' . $id . '\>',
"$srcdir/") {
print "F- $line\n" if $verbose;
next;
}
if ($expect_undoc{$id}) {
print "F- $line\n" if $verbose;
$found_undoc{$id} = 1;
next;
}
if ($id =~ /^ASN1_PCTX_\w+$/) {
print "F- $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: function $id()";
}
next;
}
if (/^int$/) {
$_ .= ' ' . <$in_fh>;
goto try_again;
}
if (/ \*$/) {
$_ .= <$in_fh>;
goto try_again;
}
# The name of the function return type is so long
# that it requires a line break afterwards.
if (/^\w{30,}$/) {
my $next_line = <$in_fh>;
if ($next_line =~ /^ {4}\w/) {
$_ .= $next_line;
goto try_again;
}
}
die "parse error: $_";
}
close $in_fh;
foreach (keys %expect_undoc) {
warn "expected as undocumented but not found: $_"
unless $found_undoc{$_};
}
exit 0;
|