]>
git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/gf-complete/tools/gf_mult.c
2 * GF-Complete: A Comprehensive Open Source Library for Galois Field Arithmetic
3 * James S. Plank, Ethan L. Miller, Kevin M. Greenan,
4 * Benjamin A. Arnold, John A. Burnum, Adam W. Disney, Allen C. McBride.
8 * Multiplies two numbers in gf_2^w
17 #include "gf_complete.h"
18 #include "gf_method.h"
19 #include "gf_general.h"
23 fprintf(stderr
, "usage: gf_mult a b w [method] - does multiplication of a and b in GF(2^w)\n");
25 fprintf(stderr
, "Bad w.\n");
26 fprintf(stderr
, "Legal w are: 1 - 32, 64 and 128.\n");
27 fprintf(stderr
, "Append 'h' to w to treat a, b and the product as hexadecimal.\n");
28 fprintf(stderr
, "w=128 is hex only (i.e. '128' will be an error - do '128h')\n");
30 if (why
== 'A') fprintf(stderr
, "Bad a\n");
31 if (why
== 'B') fprintf(stderr
, "Bad b\n");
33 fprintf(stderr
, "Bad Method Specification: ");
39 int main(int argc
, char **argv
)
46 if (argc
< 4) usage(' ');
48 if (sscanf(argv
[3], "%d", &w
) == 0) usage('W');
49 if (w
<= 0 || (w
> 32 && w
!= 64 && w
!= 128)) usage('W');
51 hex
= (strchr(argv
[3], 'h') != NULL
);
52 if (!hex
&& w
== 128) usage('W');
55 if (gf_init_easy(&gf
, w
) == 0) usage('M');
57 if (create_gf_from_argv(&gf
, w
, argc
, argv
, 4) == 0) usage('M');
60 if (!gf_general_s_to_val(&a
, w
, argv
[1], hex
)) usage('A');
61 if (!gf_general_s_to_val(&b
, w
, argv
[2], hex
)) usage('B');
63 gf_general_multiply(&gf
, &a
, &b
, &c
);
64 gf_general_val_to_s(&c
, w
, output
, hex
);
66 printf("%s\n", output
);