handle negative scalars correctly when doing point multiplication
[openssl.git] / perl / openssl_digest.xs
1
2 #include "openssl.h"
3
4 int boot_digest()
5         {
6         SSLeay_add_all_digests();
7         return(1);
8         }
9
10 MODULE =  OpenSSL::MD   PACKAGE = OpenSSL::MD   PREFIX = p5_EVP_MD_
11
12 PROTOTYPES: ENABLE
13 VERSIONCHECK: DISABLE
14
15 # OpenSSL::MD::new(name) name= md2, md5, sha, sha1, or mdc2
16 #       md->name() - returns the name
17 #       md->init() - reinitalises the digest
18 #       md->update(data) - adds more data to digest
19 #       digest=md->final() - returns digest
20 #
21
22 void
23 p5_EVP_MD_new(...)
24         PREINIT:
25                 EVP_MD_CTX *ctx;
26                 const EVP_MD *md;
27                 char *name;
28         PPCODE:
29                 if ((items == 1) && SvPOK(ST(0)))
30                         name=SvPV_nolen(ST(0));
31                 else if ((items == 2) && SvPOK(ST(1)))
32                         name=SvPV_nolen(ST(1));
33                 else
34                         croak("Usage: OpenSSL::MD::new(type)");
35                 PUSHs(sv_newmortal());
36                 md=EVP_get_digestbyname(name);
37                 if (md != NULL)
38                         {
39                         ctx=malloc(sizeof(EVP_MD_CTX));
40                         EVP_DigestInit(ctx,md);
41                         sv_setref_pv(ST(0), "OpenSSL::MD", (void*)ctx);
42                         }
43
44 datum
45 p5_EVP_MD_name(ctx)
46         EVP_MD_CTX *ctx
47         CODE:
48                 RETVAL.dptr=OBJ_nid2ln(EVP_MD_CTX_type(ctx));
49                 RETVAL.dsize=strlen(RETVAL.dptr);
50
51         OUTPUT:
52                 RETVAL
53         
54 void
55 p5_EVP_MD_init(ctx)
56         EVP_MD_CTX *ctx
57         CODE:
58                 EVP_DigestInit(ctx,EVP_MD_CTX_type(ctx));
59
60 void
61 p5_EVP_MD_update(ctx, in)
62         EVP_MD_CTX *ctx
63         datum in
64         CODE:
65                 EVP_DigestUpdate(ctx,in.dptr,in.dsize);
66
67 datum
68 p5_EVP_MD_final(ctx)
69         EVP_MD_CTX *ctx
70         PREINIT:
71                 char md[EVP_MAX_MD_SIZE];
72                 int len;
73         CODE:
74                 EVP_DigestFinal(ctx,md,&len);
75                 RETVAL.dptr=md;
76                 RETVAL.dsize=len;
77         OUTPUT:
78                 RETVAL
79
80 void
81 p5_EVP_MD_DESTROY(ctx)
82         EVP_MD_CTX *ctx
83         CODE:
84         free((char *)ctx);
85