File: CryptoPP_stubs.c

package info (click to toggle)
mldonkey 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,524 kB
  • sloc: ml: 149,175; cpp: 11,805; ansic: 8,780; sh: 4,226; asm: 3,870; xml: 1,092; perl: 102; makefile: 95
file content (93 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (5)
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
/* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA */
/*
    This file is part of mldonkey.

    mldonkey is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    mldonkey is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with mldonkey; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "CryptoPP_stubs.h"



// return private key Base64Encoded
value 
ml_createKey() {
	char buf[4096];
	createKey(buf);
	return caml_copy_string(buf);
}

// return public key
value 
ml_loadKey(value privatekey) {
  char *s = String_val(privatekey);
	char buf[4096];
	unsigned long len =	loadKey(s, buf);

  value res;
  res = caml_alloc_string(len);
  memmove(String_val(res), buf, len);

	return res;
}

value
ml_createSignature(value m_key, value m_keyLen, value m_cInt, value m_ipType, value m_ip) {

	byte *key = (byte*) String_val(m_key);
	int keyLen = Int_val(m_keyLen);
	uint32_t cInt = Int64_val(m_cInt);
	int ipType = Int_val(m_ipType);
	uint32_t ip = Int64_val(m_ip);

	byte buf[4096];

	int len = createSignature(buf, 200, key, keyLen, cInt, ipType, ip);

  value res;
  res = caml_alloc_string(len);
  memmove(String_val(res), buf, len);

	return res;
}

value 
ml_verifySignature(value m_key, value m_keyLen, value m_sig, value m_sigLen, value m_cInt, value m_ipType, value m_ip) {

	byte* key = (byte*) String_val(m_key);
	int keyLen = Int_val(m_keyLen);
	byte* sig = (byte*) String_val(m_sig);
	int sigLen = Int_val(m_sigLen);
	uint32_t cInt = Int64_val(m_cInt);
	int ipType = Int_val(m_ipType);
	uint32_t ip = Int64_val(m_ip);
	
	return Val_bool( 
			verifySignature(key, keyLen, sig, sigLen, cInt, ipType, ip)
	);
}

value
ml_verifySignature_bytecode(value *argv, int argn) {
	return ml_verifySignature(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
}

void cc_lprintf_nl(const char * msg, int verb)
{
  static value * caml_func = NULL;
  if (caml_func == NULL) caml_func = caml_named_value("ml_lprintf_nl");
  caml_callback2(*caml_func, caml_copy_string(msg), Val_int(verb));
}