summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/bn_dump.3
diff options
context:
space:
mode:
authorschwarze <>2015-11-12 00:55:49 +0000
committerschwarze <>2015-11-12 00:55:49 +0000
commitd87f13d29bdce02ae37ef5da3fb9e0227724e57b (patch)
tree7050351f491582d85dae8d06f9530073074006fe /src/lib/libcrypto/man/bn_dump.3
parent3681e43b7101c2171779b147addaa726f1373b2b (diff)
downloadopenbsd-d87f13d29bdce02ae37ef5da3fb9e0227724e57b.tar.gz
openbsd-d87f13d29bdce02ae37ef5da3fb9e0227724e57b.tar.bz2
openbsd-d87f13d29bdce02ae37ef5da3fb9e0227724e57b.zip
Convert the handful of manuals that had imaginary names,
give them names that really exist. This also helps jmc@'s ongoing work on improving NAME sections.
Diffstat (limited to 'src/lib/libcrypto/man/bn_dump.3')
-rw-r--r--src/lib/libcrypto/man/bn_dump.3713
1 files changed, 713 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/bn_dump.3 b/src/lib/libcrypto/man/bn_dump.3
new file mode 100644
index 0000000000..2f1bda9bb5
--- /dev/null
+++ b/src/lib/libcrypto/man/bn_dump.3
@@ -0,0 +1,713 @@
1.Dd $Mdocdate: November 12 2015 $
2.Dt BN_DUMP 3
3.Os
4.Sh NAME
5.Nm bn_mul_words ,
6.Nm bn_mul_add_words ,
7.Nm bn_sqr_words ,
8.Nm bn_div_words ,
9.Nm bn_add_words ,
10.Nm bn_sub_words ,
11.Nm bn_mul_comba4 ,
12.Nm bn_mul_comba8 ,
13.Nm bn_sqr_comba4 ,
14.Nm bn_sqr_comba8 ,
15.Nm bn_cmp_words ,
16.Nm bn_mul_normal ,
17.Nm bn_mul_low_normal ,
18.Nm bn_mul_recursive ,
19.Nm bn_mul_part_recursive ,
20.Nm bn_mul_low_recursive ,
21.Nm bn_mul_high ,
22.Nm bn_sqr_normal ,
23.Nm bn_sqr_recursive ,
24.Nm bn_expand ,
25.Nm bn_wexpand ,
26.Nm bn_expand2 ,
27.Nm bn_fix_top ,
28.Nm bn_check_top ,
29.Nm bn_print ,
30.Nm bn_dump ,
31.Nm bn_set_max ,
32.Nm bn_set_high ,
33.Nm bn_set_low ,
34.Nm sqr
35.Nd BIGNUM library internal functions
36.Sh SYNOPSIS
37.In openssl/bn.h
38.Ft BN_ULONG
39.Fo bn_mul_words
40.Fa "BN_ULONG *rp"
41.Fa "BN_ULONG *ap"
42.Fa "int num"
43.Fa "BN_ULONG w"
44.Fc
45.Ft BN_ULONG
46.Fo bn_mul_add_words
47.Fa "BN_ULONG *rp"
48.Fa "BN_ULONG *ap"
49.Fa "int num"
50.Fa "BN_ULONG w"
51.Fc
52.Ft void
53.Fo bn_sqr_words
54.Fa "BN_ULONG *rp"
55.Fa "BN_ULONG *ap"
56.Fa "int num"
57.Fc
58.Ft BN_ULONG
59.Fo bn_div_words
60.Fa "BN_ULONG h"
61.Fa "BN_ULONG l"
62.Fa "BN_ULONG d"
63.Fc
64.Ft BN_ULONG
65.Fo bn_add_words
66.Fa "BN_ULONG *rp"
67.Fa "BN_ULONG *ap"
68.Fa "BN_ULONG *bp"
69.Fa "int num"
70.Fc
71.Ft BN_ULONG
72.Fo bn_sub_words
73.Fa "BN_ULONG *rp"
74.Fa "BN_ULONG *ap"
75.Fa "BN_ULONG *bp"
76.Fa "int num"
77.Fc
78.Ft void
79.Fo bn_mul_comba4
80.Fa "BN_ULONG *r"
81.Fa "BN_ULONG *a"
82.Fa "BN_ULONG *b"
83.Fc
84.Ft void
85.Fo bn_mul_comba8
86.Fa "BN_ULONG *r"
87.Fa "BN_ULONG *a"
88.Fa "BN_ULONG *b"
89.Fc
90.Ft void
91.Fo bn_sqr_comba4
92.Fa "BN_ULONG *r"
93.Fa "BN_ULONG *a"
94.Fc
95.Ft void
96.Fo bn_sqr_comba8
97.Fa "BN_ULONG *r"
98.Fa "BN_ULONG *a"
99.Fc
100.Ft int
101.Fo bn_cmp_words
102.Fa "BN_ULONG *a"
103.Fa "BN_ULONG *b"
104.Fa "int n"
105.Fc
106.Ft void
107.Fo bn_mul_normal
108.Fa "BN_ULONG *r"
109.Fa "BN_ULONG *a"
110.Fa "int na"
111.Fa "BN_ULONG *b"
112.Fa "int nb"
113.Fc
114.Ft void
115.Fo bn_mul_low_normal
116.Fa "BN_ULONG *r"
117.Fa "BN_ULONG *a"
118.Fa "BN_ULONG *b"
119.Fa "int n"
120.Fc
121.Ft void
122.Fo bn_mul_recursive
123.Fa "BN_ULONG *r"
124.Fa "BN_ULONG *a"
125.Fa "BN_ULONG *b"
126.Fa "int n2"
127.Fa "int dna"
128.Fa "int dnb"
129.Fa "BN_ULONG *tmp"
130.Fc
131.Ft void
132.Fo bn_mul_part_recursive
133.Fa "BN_ULONG *r"
134.Fa "BN_ULONG *a"
135.Fa "BN_ULONG *b"
136.Fa "int n"
137.Fa "int tna"
138.Fa "int tnb"
139.Fa "BN_ULONG *tmp"
140.Fc
141.Ft void
142.Fo bn_mul_low_recursive
143.Fa "BN_ULONG *r"
144.Fa "BN_ULONG *a"
145.Fa "BN_ULONG *b"
146.Fa "int n2"
147.Fa "BN_ULONG *tmp"
148.Fc
149.Ft void
150.Fo bn_mul_high
151.Fa "BN_ULONG *r"
152.Fa "BN_ULONG *a"
153.Fa "BN_ULONG *b"
154.Fa "BN_ULONG *l"
155.Fa "int n2"
156.Fa "BN_ULONG *tmp"
157.Fc
158.Ft void
159.Fo bn_sqr_normal
160.Fa "BN_ULONG *r"
161.Fa "BN_ULONG *a"
162.Fa "int n"
163.Fa "BN_ULONG *tmp"
164.Fc
165.Ft void
166.Fo bn_sqr_recursive
167.Fa "BN_ULONG *r"
168.Fa "BN_ULONG *a"
169.Fa "int n2"
170.Fa "BN_ULONG *tmp"
171.Fc
172.Ft void
173.Fo mul
174.Fa "BN_ULONG r"
175.Fa "BN_ULONG a"
176.Fa "BN_ULONG w"
177.Fa "BN_ULONG c"
178.Fc
179.Ft void
180.Fo mul_add
181.Fa "BN_ULONG r"
182.Fa "BN_ULONG a"
183.Fa "BN_ULONG w"
184.Fa "BN_ULONG c"
185.Fc
186.Ft void
187.Fo sqr
188.Fa "BN_ULONG r0"
189.Fa "BN_ULONG r1"
190.Fa "BN_ULONG a"
191.Fc
192.Ft BIGNUM *
193.Fo bn_expand
194.Fa "BIGNUM *a"
195.Fa "int bits"
196.Fc
197.Ft BIGNUM *
198.Fo bn_wexpand
199.Fa "BIGNUM *a"
200.Fa "int n"
201.Fc
202.Ft BIGNUM *
203.Fo bn_expand2
204.Fa "BIGNUM *a"
205.Fa "int n"
206.Fc
207.Ft void
208.Fo bn_fix_top
209.Fa "BIGNUM *a"
210.Fc
211.Ft void
212.Fo bn_check_top
213.Fa "BIGNUM *a"
214.Fc
215.Ft void
216.Fo bn_print
217.Fa "BIGNUM *a"
218.Fc
219.Ft void
220.Fo bn_dump
221.Fa "BN_ULONG *d"
222.Fa "int n"
223.Fc
224.Ft void
225.Fo bn_set_max
226.Fa "BIGNUM *a"
227.Fc
228.Ft void
229.Fo bn_set_high
230.Fa "BIGNUM *r"
231.Fa "BIGNUM *a"
232.Fa "int n"
233.Fc
234.Ft void
235.Fo bn_set_low
236.Fa "BIGNUM *r"
237.Fa "BIGNUM *a"
238.Fa "int n"
239.Fc
240.Sh DESCRIPTION
241This page documents the internal functions used by the OpenSSL
242.Vt BIGNUM
243implementation.
244They are described here to facilitate debugging and extending the
245library.
246They are
247.Em not
248to be used by applications.
249.Ss The BIGNUM structure
250.Bd -literal
251typedef struct bignum_st BIGNUM;
252
253struct bignum_st {
254 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
255 int top; /* Index of last used d +1. */
256 /* The next are internal book keeping for bn_expand. */
257 int dmax; /* Size of the d array. */
258 int neg; /* one if the number is negative */
259 int flags;
260};
261.Ed
262.Pp
263The integer value is stored in
264.Fa d ,
265a
266.Xr malloc 3 Ap ed
267array of words
268.Pq Vt BN_ULONG ,
269least significant word first.
270A
271.Vt BN_ULONG
272can be either 16, 32 or 64 bits in size, depending on the 'number of
273bits'
274.Pq Dv BITS2
275specified in
276.In openssl/bn.h .
277.Pp
278.Fa dmax
279is the size of the
280.Fa d
281array that has been allocated.
282.Fa top
283is the number of words being used, so for a value of 4, bn.d[0]=4 and
284bn.top=1.
285.Fa neg
286is 1 if the number is negative.
287When a
288.Vt BIGNUM
289is 0, the
290.Fa d
291field can be
292.Dv NULL
293and
294.Fa top
295== 0.
296.Pp
297.Fa flags
298is a bit field of flags which are defined in
299.In openssl/bn.h .
300The flags begin with
301.Dv BN_FLG_ .
302The macros
303.Fn BN_set_flags b n
304and
305.Fn BN_get_flags b n
306exist to enable or fetch flag(s)
307.Fa n
308from a
309.Vt BIGNUM
310structure
311.Fa b .
312.Pp
313Various routines in this library require the use of temporary
314.Vt BIGNUM
315variables during their execution.
316Since dynamic memory allocation to create
317.Vt BIGNUM Ns s
318is rather expensive when used in conjunction with repeated subroutine
319calls, the
320.Vt BN_CTX
321structure is used.
322This structure contains BN_CTX_NUM
323.Vt BIGNUM Ns s,
324see
325.Xr BN_CTX_start 3 .
326.Ss Low-level arithmetic operations
327These functions are implemented in C and for several platforms in
328assembly language:
329.Pp
330.Fn bn_mul_words rp ap num w
331operates on the
332.Fa num
333word arrays
334.Fa rp
335and
336.Fa ap .
337It computes
338.Fa ap
339*
340.Fa w ,
341places the result in
342.Fa rp ,
343and returns the high word (carry).
344.Pp
345.Fn bn_mul_add_words rp ap num w
346operates on the
347.Fa num
348word arrays
349.Fa rp
350and
351.Fa ap .
352It computes
353.Fa ap
354*
355.Fa w
356+
357.Fa rp ,
358places the result in
359.Fa rp ,
360and returns the high word (carry).
361.Pp
362.Fn bn_sqr_words rp ap num
363operates on the
364.Fa num
365word array
366.Fa ap
367and the
368.Pf 2* Fa num
369word array
370.Fa ap .
371It computes
372.Fa ap
373*
374.Fa ap
375word-wise, and places the low and high bytes of the result in
376.Fa rp .
377.Pp
378.Fn bn_div_words h l d
379divides the two word number
380.Pq Fa h , Fa l
381by
382.Fa d
383and returns the result.
384.Pp
385.Fn bn_add_words rp ap bp num
386operates on the
387.Fa num
388word arrays
389.Fa ap ,
390.Fa bp
391and
392.Fa rp .
393It computes
394.Fa ap
395+
396.Fa bp ,
397places the result in
398.Fa rp ,
399and returns the high word (carry).
400.Pp
401.Fn bn_sub_words rp ap bp num
402operates on the
403.Fa num
404word arrays
405.Fa ap ,
406.Fa bp
407and
408.Fa rp .
409It computes
410.Fa ap
411-
412.Fa bp ,
413places the result in
414.Fa rp ,
415and returns the carry (1 if
416.Fa bp
417\(ra
418.Fa ap ,
4190 otherwise).
420.Pp
421.Fn bn_mul_comba4 r a b
422operates on the 4 word arrays
423.Fa a
424and
425.Fa b
426and the 8 word array
427.Fa r .
428It computes
429.Fa a Ns * Ns Fa b
430and places the result in
431.Fa r .
432.Pp
433.Fn bn_mul_comba8 r a b
434operates on the 8 word arrays
435.Fa a
436and
437.Fa b
438and the 16 word array
439.Fa r .
440It computes
441.Fa a Ns * Ns Fa b
442and places the result in
443.Fa r .
444.Pp
445.Fn bn_sqr_comba4 r a b
446operates on the 4 word arrays
447.Fa a
448and
449.Fa b
450and the 8 word array
451.Fa r .
452.Pp
453.Fn bn_sqr_comba8 r a b
454operates on the 8 word arrays
455.Fa a
456and
457.Fa b
458and the 16 word array
459.Fa r .
460.Pp
461The following functions are implemented in C:
462.Pp
463.Fn bn_cmp_words a b n
464operates on the
465.Fa n
466word arrays
467.Fa a
468and
469.Fa b .
470It returns 1, 0 and -1 if
471.Fa a
472is greater than, equal and less than
473.Fa b .
474.Pp
475.Fn bn_mul_normal r a na b nb
476operates on the
477.Fa na
478word array
479.Fa a ,
480the
481.Fa nb
482word array
483.Fa b
484and the
485.Fa na Ns + Ns Fa nb
486word array
487.Fa r .
488It computes
489.Fa a Ns * Ns Fa b
490and places the result in
491.Fa r .
492.Pp
493.Fn bn_mul_low_normal r a b n
494operates on the
495.Fa n
496word arrays
497.Fa r ,
498.Fa a
499and
500.Fa b .
501It computes the
502.Fa n
503low words of
504.Fa a Ns * Ns Fa b
505and places the result in
506.Fa r .
507.Pp
508.Fn bn_mul_recursive r a b n2 dna dnb t
509operates on the word arrays
510.Fa a
511and
512.Fa b
513of length
514.Fa n2 Ns + Ns Fa dna
515and
516.Fa n2 Ns + Ns Fa dnb
517.Pf ( Fa dna
518and
519.Fa dnb
520are currently allowed to be 0 or negative) and the
521.Pf 2* Fa n2
522word arrays
523.Fa r
524and
525.Sy t .
526.Fa n2
527must be a power of 2.
528It computes
529.Fa a Ns * Ns Fa b
530and places the result in
531.Fa r .
532.Pp
533.Fn bn_mul_part_recursive r a b n tna tnb tmp
534operates on the word arrays
535.Fa a
536and
537.Fa b
538of length
539.Fa n Ns + Ns Fa tna
540and
541.Fa n Ns + Ns Fa tnb
542and the
543.Pf 4* Fa n
544word arrays
545.Fa r
546and
547.Fa tmp .
548.Pp
549.Fn bn_mul_low_recursive r a b n2 tmp
550operates on the
551.Fa n2
552word arrays
553.Fa r
554and
555.Fa tmp
556and the
557.Fa n2 Ns /2
558word arrays
559.Fa a
560and
561.Fa b .
562.Pp
563.Fn bn_mul_high r a b l n2 tmp
564operates on the
565.Fa n2
566word arrays
567.Fa r ,
568.Fa a ,
569.Fa b
570and
571.Fa l
572(?) and the
573.Pf 3* Fa n2
574word array
575.Fa tmp .
576.Pp
577.Xr BN_mul 3
578calls
579.Fn bn_mul_normal ,
580or an optimized implementation if the factors have the same size:
581.Fn bn_mul_comba8
582is used if they are 8 words long,
583.Fn bn_mul_recursive
584if they are larger than
585.Dv BN_MULL_SIZE_NORMAL
586and the size is an exact multiple of the word size, and
587.Fn bn_mul_part_recursive
588for others that are larger than
589.Dv BN_MULL_SIZE_NORMAL .
590.Pp
591.Fn bn_sqr_normal r a n tmp
592operates on the
593.Fa n
594word array
595.Fa a
596and the
597.Pf 2* Fa n
598word arrays
599.Fa tmp
600and
601.Fa r .
602.Pp
603The implementations use the following macros which, depending on the
604architecture, may use
605.Vt long long
606C operations or inline assembler.
607They are defined in
608.Pa bn_lcl.h .
609.Pp
610.Fn mul r a w c
611computes
612.Fa w Ns * Ns Fa a Ns + Ns Fa c
613and places the low word of the result in
614.Fa r
615and the high word in
616.Fa c .
617.Pp
618.Fn mul_add r a w c
619computes
620.Fa w Ns * Ns Fa a Ns + Ns Fa r Ns + Ns Fa c
621and places the low word of the result in
622.Fa r
623and the high word in
624.Fa c .
625.Pp
626.Fn sqr r0 r1 a
627computes
628.Fa a Ns * Ns Fa a
629and places the low word of the result in
630.Fa r0
631and the high word in
632.Fa r1 .
633.Ss Size changes
634.Fn bn_expand
635ensures that
636.Fa b
637has enough space for a
638.Fa bits
639bit number.
640.Fn bn_wexpand
641ensures that
642.Fa b
643has enough space for an
644.Fa n
645word number.
646If the number has to be expanded, both macros call
647.Fn bn_expand2 ,
648which allocates a new
649.Fa d
650array and copies the data.
651They return
652.Dv NULL
653on error,
654.Fa b
655otherwise.
656.Pp
657The
658.Fn bn_fix_top
659macro reduces
660.Fa a Ns -> Ns Fa top
661to point to the most significant non-zero word plus one when
662.Fa a
663has shrunk.
664.Ss Debugging
665.Fn bn_check_top
666verifies that
667.Ql ((a)-\(ratop \(ra= 0 && (a)-\(ratop \(la= (a)-\(radmax) .
668A violation will cause the program to abort.
669.Pp
670.Fn bn_print
671prints
672.Fa a
673to
674.Dv stderr .
675.Fn bn_dump
676prints
677.Fa n
678words at
679.Fa d
680(in reverse order, i.e.
681most significant word first) to
682.Dv stderr .
683.Pp
684.Fn bn_set_max
685makes
686.Fa a
687a static number with a
688.Fa dmax
689of its current size.
690This is used by
691.Fn bn_set_low
692and
693.Fn bn_set_high
694to make
695.Fa r
696a read-only
697.Vt BIGNUM
698that contains the
699.Fa n
700low or high words of
701.Fa a .
702.Pp
703If
704.Dv BN_DEBUG
705is not defined,
706.Fn bn_check_top ,
707.Fn bn_print ,
708.Fn bn_dump
709and
710.Fn bn_set_max
711are defined as empty macros.
712.Sh SEE ALSO
713.Xr bn 3