started with python binding

This commit is contained in:
TLINDEN
2014-12-14 14:38:30 +01:00
parent 6f47b86f98
commit 9e71b84c85
9 changed files with 886 additions and 0 deletions

8
bindings/py/Makefile.am Normal file
View File

@@ -0,0 +1,8 @@
all:
python setup.py build
install:
python setup.py install
clean:
rm -rf build

73
bindings/py/gencffi.pl Executable file
View File

@@ -0,0 +1,73 @@
#!/usr/bin/perl
use Data::Dumper;
my %sobytes = (
'crypto_box_NONCEBYTES' => 24,
'crypto_box_PUBLICKEYBYTES' => 32,
'crypto_box_SECRETKEYBYTES' => 32,
'crypto_box_ZEROBYTES' => 32,
'crypto_box_BOXZEROBYTES' => 16,
'crypto_box_MACBYTES' => 16,
'crypto_secretbox_KEYBYTES' => 32,
'crypto_secretbox_NONCEBYTES' => 24,
'crypto_secretbox_ZEROBYTES' => 32,
'crypto_secretbox_BOXZEROBYTES' => 16,
'crypto_secretbox_MACBYTES' => 16,
'crypto_sign_PUBLICKEYBYTES' => 32,
'crypto_sign_SECRETKEYBYTES' => 64,
'crypto_sign_SEEDBYTES' => 32,
'crypto_sign_BYTES' => 64,
'crypto_stream_KEYBYTES' => 32,
'crypto_stream_NONCEBYTES' => 24,
'crypto_generichash_BYTES' => 32,
'crypto_scalarmult_curve25519_BYTES' => 32,
'crypto_scalarmult_BYTES' => 32,
'crypto_generichash_BYTES_MAX' => 64,
);
my @code;
foreach my $head (@ARGV) {
open HEAD, "<$head" or die "Could not open $head: $!\n";
my $raw = join '', <HEAD>;
# resolve sodium constants
foreach my $sobyte (sort { length($b) <=> length($a) } keys %sobytes) {
$raw =~ s/$sobyte/$sobytes{$sobyte}/g;
}
# some sizes are calculated, cffi doesn't so do we
$raw =~ s/(\d+) \+ (\d+)/$1 + $2/ge;
# 1line type
while ($raw =~ /^(typedef .*;)/gm) {
push @code, ('', "/*** $0: from $head:$. */");
push @code, $1;
}
# a struct
# the uthash handle doesn't resolve, so we
# use a placeholder
while ($raw =~ /(struct [^\s]* \{[^\}]*\};)/gs) {
my $code = $1;
$code =~ s/UT_hash_handle hh/byte hh[56]/g;
push @code, ('', "/*** $0: from $head:$. */");
push @code, $code;
}
# a function
while ($raw =~ /^([a-zA-Z].*\(.*\);)/gm) {
my $c = $1;
push @code, ('', "/*** $0: from $head:$. */");
push @code, $c;
}
close $head;
}
print "PCP_RAW_CODE = '''\n";
print join "\n", @code;
print "'''\n";

View File

@@ -0,0 +1,25 @@
from cffi import FFI
from pypcp.dll import *
__all__ = ('raw Key'.split() )
class Key(object):
def __init__(self, owner=None, mail=None, sk=None):
self._sk = None
if owner or mail:
if not owner:
owner=''
if not mail:
mail=''
self.generate(owner, mail)
def generate(self, owner=None, mail=None):
self._sk = libpcp.pcpkey_new()
if owner:
libpcp.pcpkey_setowner(self._sk, owner, mail)
def dump(self):
if self._sk:
libpcp.pcp_dumpkey(self._sk)

10
bindings/py/pypcp/dll.py Normal file
View File

@@ -0,0 +1,10 @@
from raw import *
from static import *
from cffi import FFI
ffi = FFI()
libpcp = ffi.dlopen('libpcp1.so.0')
ffi.cdef("%s\n%s\n" % (STATIC, PCP_RAW_CODE))

669
bindings/py/pypcp/raw.py Normal file
View File

@@ -0,0 +1,669 @@
PCP_RAW_CODE = '''
/*** bindings/py/gencffi.pl: from include/pcp/defines.h:187 */
typedef unsigned char byte;
/*** bindings/py/gencffi.pl: from include/pcp/defines.h:187 */
typedef unsigned short dbyte;
/*** bindings/py/gencffi.pl: from include/pcp/defines.h:187 */
typedef unsigned int qbyte;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_key_t pcp_key_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_pubkey_t pcp_pubkey_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pbp_pubkey_t pbp_pubkey_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_rec_t pcp_rec_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_keysig_t pcp_keysig_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_ctx_t PCPCTX;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _vault_t vault_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _vault_header_t vault_header_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _vault_item_header_t vault_item_header_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_buffer Buffer;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_stream_t Pcpstream;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_rfc_pubkey_header_t rfc_pub_h;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_rfc_pubkey_0x21_t rfc_pub_k;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_rfc_pubkey_sigheader_0x21_t rfc_pub_sig_h;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_rfc_pubkey_sigsub_0x21_t rfc_pub_sig_s;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
typedef struct _pcp_ks_bundle_t pcp_ks_bundle_t;
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_key_t {
byte masterpub[32]; /**< ED25519 master public key signing key */
byte mastersecret[64]; /**< ED25519 master secret key signing key */
byte pub[32]; /**< Curve25519 encryption public key */
byte secret[32]; /**< Curve25519 encryption secret key */
byte edpub[32]; /**< ED25519 public signing key */
byte edsecret[64]; /**< ED25519 secret signing key */
byte nonce[24]; /**< random nonce used to encrypt secret keys */
byte encrypted[176]; /**< concatenated and encrypted secret keys */
char owner[255]; /**< the key owner, string */
char mail[255]; /**< mail address of the owner, string */
char id[17]; /**< key-id, used internally only, jenhash of public keys */
uint8_t type; /**< key type: MASTER_SECRET or SECRET */
uint64_t ctime; /**< creation time, epoch */
uint32_t version; /**< key version */
uint32_t serial; /**< serial number of the key, randomly generated */
byte hh[56];
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_pubkey_t {
byte masterpub[32]; /**< ED25519 master public key signing key */
byte sigpub[32]; /**< ED25519 public signing key */
byte pub[32]; /**< Curve25519 encryption public key */
byte edpub[32]; /**< ED25519 public signing key (FIXME: huh? 2 of them???) */
char owner[255]; /**< the key owner, string */
char mail[255]; /**< mail address of the owner, string */
char id[17]; /**< key-id, used internally only, jenhash of public keys */
uint8_t type; /**< key type: MASTER_SECRET or SECRET */
uint64_t ctime; /**< creation time, epoch */
uint32_t version; /**< key version */
uint32_t serial; /**< serial number of the key, randomly generated */
uint8_t valid; /**< 1 if import signature verified, 0 if not */
byte signature[128]; /**< raw binary blob of pubkey export signature */
byte hh[56];
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pbp_pubkey_t {
byte sigpub[32];
byte edpub[32];
byte pub[32];
char iso_ctime[32];
char iso_expire[32];
char name[1024];
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_rec_t {
size_t ciphersize; /**< the size of the encrypted recipient list */
byte *cipher; /**< contains the whole encrypted recipient list */
pcp_key_t *secret; /**< the secret key of the recipient for signing */
pcp_pubkey_t *pub; /**< if verification were ok, contains the public key of the signer */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_keysig_t {
uint8_t type;
uint32_t size;
char id[17];
byte checksum[32];
byte *blob;
byte hh[56];
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_ctx_t {
char *pcp_err; /**< last error message. retrieve with fatals_ifany() */
byte pcp_errset; /**< indicates if an error occurred. */
int pcp_exit; /**< exit code for pcp commandline utility */
int verbose; /**< enable verbose output */
pcp_key_t *pcpkey_hash; /**< hash containing for keys */
pcp_pubkey_t *pcppubkey_hash; /**< hash for keys. */
pcp_keysig_t *pcpkeysig_hash; /**< hash for key sigs */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _vault_t {
char *filename; /**< The filename of the vault (full path) */
FILE *fd; /**< Filehandle if opened */
uint8_t unsafed; /**< Flag to tell if the file needs to be written */
uint8_t isnew; /**< Flag to tell if the vault has been newly created */
uint32_t size; /**< Filesize */
time_t modified; /**< mtime */
mode_t mode; /**< File mode */
uint32_t version; /**< Vault version */
byte checksum[32]; /**< SHA256 checksum over the whole vault */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _vault_header_t {
uint8_t fileid; /**< File id, proprietary. Marks the vault as a vault */
uint32_t version; /**< File version */
byte checksum[32]; /**< SHA256 checksum over the whole vault */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _vault_item_header_t {
uint8_t type; /**< Item type (secret key, public, key, keysig, \see _PCP_KEY_TYPES */
uint32_t size; /**< Size of the item */
uint32_t version; /**< Version of the item */
byte checksum[32]; /**< SHA256 checksum of the item */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_buffer {
char *name; /**< just for convenience in error messages and the like, so we know which buffer cause trouble */
uint8_t allocated; /**< marks the buffer as allocated */
size_t blocksize; /**< the blocksize to use when resizing, also used for initial malloc() */
size_t size; /**< stores the current allocated size of the object */
size_t offset; /**< current read position */
size_t end; /**< current write position, data end. maybe less than size. */
uint8_t isstring; /**< treat as char array/string */
void *buf; /**< the actual storage buffer */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_stream_t {
FILE *fd; /**< The backend FILE stream */
Buffer *b; /**< The backend Buffer object */
Buffer *cache; /**< The caching Buffer object (for look ahead read) */
Buffer *next; /**< The caching Next-Buffer object (for look ahead read) */
Buffer *save; /**< Temporary buffer to backup overflow data */
uint8_t is_buffer; /**< Set to 1 if the backend is a Buffer */
uint8_t eof; /**< Set to 1 if EOF reached */
uint8_t err; /**< Set to 1 if an error occured */
uint8_t armor; /**< Set to 1 if Z85 en/de-coding is requested */
uint8_t determine; /**< Set to 1 to automatically determine armor mode */
uint8_t firstread; /**< Internal flag, will be set after first read() */
size_t linewr; /**< Used for Z85 writing, number of chars written on last line */
size_t blocksize; /**< Blocksize used for z85, if requested */
uint8_t is_output; /**< marks the stream as output stream */
uint8_t have_begin; /**< flag to indicate we already got the begin header, if any */
size_t pos; /**< remember i/o position */
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_rfc_pubkey_header_t {
uint8_t version;
uint64_t ctime;
uint8_t cipher;
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_rfc_pubkey_0x21_t {
byte sig_ed25519_pub[32];
byte ed25519_pub[32];
byte curve25519_pub[32];
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_rfc_pubkey_sigheader_0x21_t {
uint8_t version;
uint8_t type;
uint8_t pkcipher;
uint8_t hashcipher;
uint16_t numsubs;
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_rfc_pubkey_sigsub_0x21_t {
uint32_t size;
uint8_t type;
};
/*** bindings/py/gencffi.pl: from include/pcp/structs.h:571 */
struct _pcp_ks_bundle_t {
pcp_pubkey_t *p;
pcp_keysig_t *s;
};
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_key_t *pcpkey_new ();
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
void pcp_keypairs(byte *msk, byte *mpk, byte *csk, byte *cpk, byte *esk, byte *epk);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
char *pcppubkey_get_art(pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
char *pcpkey_get_art(pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_key_t *pcpkey_encrypt(PCPCTX *ptx, pcp_key_t *key, char *passphrase);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_key_t *pcpkey_decrypt(PCPCTX *ptx, pcp_key_t *key, char *passphrase);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_pubkey_t *pcpkey_pub_from_secret(pcp_key_t *key);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
char *pcp_getkeyid(pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
char *pcp_getpubkeyid(pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
byte *pcppubkey_getchecksum(pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
byte *pcpkey_getchecksum(pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_key_t * key2be(pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_key_t *key2native(pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_pubkey_t * pubkey2be(pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
byte * pcp_gennonce();
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
byte *pcp_derivekey(PCPCTX *ptx, char *passphrase, byte *nonce);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
void pcp_seckeyblob(Buffer *b, pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
void pcp_pubkeyblob(Buffer *b, pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
Buffer *pcp_keyblob(void *k, int type);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
int pcp_sanitycheck_pub(PCPCTX *ptx, pcp_pubkey_t *key);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
int pcp_sanitycheck_key(PCPCTX *ptx, pcp_key_t *key);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
void pcp_dumpkey(pcp_key_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
void pcp_dumppubkey(pcp_pubkey_t *k);
/*** bindings/py/gencffi.pl: from include/pcp/key.h:888 */
void pcpkey_setowner(pcp_key_t *key, char *owner, char *mail);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
Buffer *buffer_new(size_t blocksize, char *name);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
Buffer *buffer_new_str(char *name);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
Buffer *buffer_new_buf(char *name, void *data, size_t datasize);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_init(Buffer *b, size_t blocksize, char *name);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_free(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_clear(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_rewind(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add(Buffer *b, const void *data, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add_buf(Buffer *dst, Buffer *src);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add_str(Buffer *b, const char * fmt, ...);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add_hex(Buffer *b, void *data, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_resize(Buffer *b, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
int buffer_done(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_get_chunk(Buffer *b, void *buf, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_get_chunk_tobuf(Buffer *b, Buffer *dst, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
byte *buffer_get(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
char *buffer_get_str(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
byte *buffer_get_remainder(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_extract(Buffer *b, void *buf, size_t offset, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_fwd_offset(Buffer *b, size_t fwdby);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_dump(const Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_info(const Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_size(const Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_left(const Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint8_t buffer_get8(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint16_t buffer_get16(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint32_t buffer_get32(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint64_t buffer_get64(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint16_t buffer_get16na(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint32_t buffer_get32na(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint64_t buffer_get64na(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint8_t buffer_last8(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint16_t buffer_last16(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint32_t buffer_last32(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
uint64_t buffer_last64(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
size_t buffer_fd_read(Buffer *b, FILE *in, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add8(Buffer *b, uint8_t v);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add16(Buffer *b, uint16_t v);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add32(Buffer *b, uint32_t v);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add64(Buffer *b, uint64_t v);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add16be(Buffer *b, uint16_t v);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add32be(Buffer *b, uint32_t v);
/*** bindings/py/gencffi.pl: from include/pcp/buffer.h:1543 */
void buffer_add64be(Buffer *b, uint64_t v);
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
PCPCTX *ptx_new();
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
void ptx_clean(PCPCTX *ptx);
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
void fatal(PCPCTX *ptx, const char * fmt, ...);
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
void fatals_ifany(PCPCTX *ptx);
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
void fatals_reset(PCPCTX *ptx);
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
void final(const char * fmt, ...);
/*** bindings/py/gencffi.pl: from include/pcp/context.h:1639 */
void ptx_dump(PCPCTX *ptx);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
byte *pcp_ed_sign(byte *message, size_t messagesize, pcp_key_t *s);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
byte *pcp_ed_verify(PCPCTX *ptx, byte *signature, size_t siglen, pcp_pubkey_t *p);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
byte *pcp_ed_verify_key(PCPCTX *ptx, byte *signature, size_t siglen, pcp_pubkey_t *p);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
size_t pcp_ed_sign_buffered(PCPCTX *ptx, Pcpstream *in, Pcpstream *out, pcp_key_t *s, int z85);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
pcp_pubkey_t *pcp_ed_verify_buffered(PCPCTX *ptx, Pcpstream *in, pcp_pubkey_t *p);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
size_t pcp_ed_detachsign_buffered(Pcpstream *in, Pcpstream *out, pcp_key_t *s);
/*** bindings/py/gencffi.pl: from include/pcp/ed.h:1935 */
pcp_pubkey_t *pcp_ed_detachverify_buffered(PCPCTX *ptx, Pcpstream *in, Pcpstream *sigfd, pcp_pubkey_t *p);
/*** bindings/py/gencffi.pl: from include/pcp/crypto.h:2223 */
size_t pcp_encrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t *s, pcp_pubkey_t *p, int signcrypt, int anon);
/*** bindings/py/gencffi.pl: from include/pcp/crypto.h:2223 */
size_t pcp_encrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, byte *symkey, int havehead, pcp_rec_t *recsign);
/*** bindings/py/gencffi.pl: from include/pcp/crypto.h:2223 */
size_t pcp_decrypt_stream(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, pcp_key_t *s, byte *symkey, int verify, int anon);
/*** bindings/py/gencffi.pl: from include/pcp/crypto.h:2223 */
size_t pcp_decrypt_stream_sym(PCPCTX *ptx, Pcpstream *in, Pcpstream* out, byte *symkey, pcp_rec_t *recverify);
/*** bindings/py/gencffi.pl: from include/pcp/crypto.h:2223 */
pcp_rec_t *pcp_rec_new(byte *cipher, size_t clen, pcp_key_t *secret, pcp_pubkey_t *pub);
/*** bindings/py/gencffi.pl: from include/pcp/crypto.h:2223 */
void pcp_rec_free(pcp_rec_t *r);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
vault_t *pcpvault_init(PCPCTX *ptx, char *filename);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
vault_t *pcpvault_new(PCPCTX *ptx, char *filename, int is_tmp);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_create(PCPCTX *ptx, vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_additem(PCPCTX *ptx, vault_t *vault, void *item, size_t itemsize, uint8_t type);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_addkey(PCPCTX *ptx, vault_t *vault, void *item, uint8_t type);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_close(PCPCTX *ptx, vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
void pcpvault_free(vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_fetchall(PCPCTX *ptx, vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_writeall(PCPCTX *ptx, vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
int pcpvault_copy(PCPCTX *ptx, vault_t *tmp, vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
void pcpvault_unlink(vault_t *tmp);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
byte *pcpvault_create_checksum(PCPCTX *ptx);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
void pcpvault_update_checksum(PCPCTX *ptx, vault_t *vault);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
vault_header_t * vh2be(vault_header_t *h);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
vault_header_t * vh2native(vault_header_t *h);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
vault_item_header_t * ih2be(vault_item_header_t *h);
/*** bindings/py/gencffi.pl: from include/pcp/vault.h:2453 */
vault_item_header_t * ih2native(vault_item_header_t *h);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
Pcpstream *ps_init(void);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
Pcpstream *ps_new_file(FILE *backendfd);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
Pcpstream *ps_new_inbuffer(Buffer *b);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
Pcpstream *ps_new_outbuffer();
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_finish(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_print(Pcpstream *stream, const char * fmt, ...);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_tell(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
Buffer *ps_buffer(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
void ps_close(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
int ps_end(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
int ps_err(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
void ps_setdetermine(Pcpstream *stream, size_t blocksize);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
void ps_armor(Pcpstream *stream, size_t blocksize);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
void ps_unarmor(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_read_decode(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
void ps_determine(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_read_next(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_read_cached(Pcpstream *stream, void *buf, size_t readbytes);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_read_raw(Pcpstream *stream, void *buf, size_t readbytes);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
void ps_write_encode(Pcpstream *stream, Buffer *dst);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
size_t ps_write_buf(Pcpstream *stream, Buffer *z);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
int ps_left(Pcpstream *stream);
/*** bindings/py/gencffi.pl: from include/pcp/pcpstream.h:2744 */
int ps_readline(Pcpstream *stream, Buffer *line);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
byte *pcp_padfour(byte *src, size_t srclen, size_t *dstlen);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
size_t pcp_unpadfour(byte *src, size_t srclen);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
byte *pcp_z85_decode(PCPCTX *ptx, char *z85block, size_t *dstlen);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
char *pcp_z85_encode(byte *raw, size_t srclen, size_t *dstlen, int doblock);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
char *pcp_readz85file(PCPCTX *ptx, FILE *infile);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
char *pcp_readz85string(PCPCTX *ptx, byte *input, size_t bufsize);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
uint8_t is_utf8(const byte * bytes);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
size_t _buffer_is_binary(byte *buf, size_t len);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
uint8_t _parse_zchar(Buffer *z, uint8_t c, uint8_t is_comment);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
long int z85_header_startswith(Buffer *buf, char *what);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
int z85_isheader(Buffer *buf);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
int z85_isend(Buffer *buf);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
int z85_isbegin(Buffer *buf);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
int z85_iscomment(Buffer *buf);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
int z85_isempty(Buffer *line);
/*** bindings/py/gencffi.pl: from include/pcp/z85.h:2922 */
int z85_isencoded(Buffer *line);'''

View File

@@ -0,0 +1,11 @@
STATIC = '''
typedef long time_t;
typedef uint16_t mode_t;
'''

23
bindings/py/setup.py Normal file
View File

@@ -0,0 +1,23 @@
import os
from setuptools import setup, find_packages
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name = "pypcp",
version = "0.2.3",
author = "Thomas von Dein",
author_email = "tlinden@cpan.org",
description = ("python libpcp wrapper"),
license = "GPL",
keywords = "cryptography API NaCl libpcp",
url = "https://github.com/tlinden/pcp/bindings/py",
packages = find_packages(),
#long_description=read('README.md'),
classifiers = ["Development Status :: 4 - Beta",
"License :: OSI Approved :: GPL",
"Topic :: Security :: Cryptography",
"Topic :: Security",
],
)

60
bindings/py/sodiumbytes.py Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/local/bin/python
from ctypes import *
import platform
if platform.system() == 'Windows':
sodium = cdll.LoadLibrary("libsodium")
pcp = cdll.LoadLibrary("libpcp1")
elif platform.system() == 'Darwin':
sodium = cdll.LoadLibrary('libsodium.dylib')
pcp = cdll.LoadLibrary("libpcp1.dylib")
else:
sodium = cdll.LoadLibrary("libsodium.so")
pcp = cdll.LoadLibrary("libpcp1.so")
crypto_box_NONCEBYTES = sodium.crypto_box_noncebytes()
crypto_box_PUBLICKEYBYTES = sodium.crypto_box_publickeybytes()
crypto_box_SECRETKEYBYTES = sodium.crypto_box_secretkeybytes()
crypto_box_ZEROBYTES = sodium.crypto_box_zerobytes()
crypto_box_BOXZEROBYTES = sodium.crypto_box_boxzerobytes()
crypto_box_MACBYTES = sodium.crypto_box_macbytes()
crypto_secretbox_KEYBYTES = sodium.crypto_secretbox_keybytes()
crypto_secretbox_NONCEBYTES = sodium.crypto_secretbox_noncebytes()
crypto_secretbox_ZEROBYTES = sodium.crypto_secretbox_zerobytes()
crypto_secretbox_BOXZEROBYTES = sodium.crypto_secretbox_boxzerobytes()
crypto_secretbox_MACBYTES = sodium.crypto_secretbox_macbytes()
crypto_sign_PUBLICKEYBYTES = sodium.crypto_sign_publickeybytes()
crypto_sign_SECRETKEYBYTES = sodium.crypto_sign_secretkeybytes()
crypto_sign_SEEDBYTES = sodium.crypto_sign_seedbytes()
crypto_sign_BYTES = sodium.crypto_sign_bytes()
crypto_stream_KEYBYTES = sodium.crypto_stream_keybytes()
crypto_stream_NONCEBYTES = sodium.crypto_stream_noncebytes()
crypto_generichash_BYTES = sodium.crypto_generichash_bytes()
crypto_scalarmult_curve25519_BYTES = sodium.crypto_scalarmult_curve25519_bytes()
crypto_scalarmult_BYTES = sodium.crypto_scalarmult_bytes()
crypto_generichash_BYTES_MAX = sodium.crypto_generichash_bytes_max()
print "'crypto_box_NONCEBYTES' => %d," % crypto_box_NONCEBYTES
print "'crypto_box_PUBLICKEYBYTES' => %d," % crypto_box_PUBLICKEYBYTES
print "'crypto_box_SECRETKEYBYTES' => %d," % crypto_box_SECRETKEYBYTES
print "'crypto_box_ZEROBYTES' => %d," % crypto_box_ZEROBYTES
print "'crypto_box_BOXZEROBYTES' => %d," % crypto_box_BOXZEROBYTES
print "'crypto_box_MACBYTES' => %d," % crypto_box_MACBYTES
print "'crypto_secretbox_KEYBYTES' => %d," % crypto_secretbox_KEYBYTES
print "'crypto_secretbox_NONCEBYTES' => %d," % crypto_secretbox_NONCEBYTES
print "'crypto_secretbox_ZEROBYTES' => %d," % crypto_secretbox_ZEROBYTES
print "'crypto_secretbox_BOXZEROBYTES' => %d," % crypto_secretbox_BOXZEROBYTES
print "'crypto_secretbox_MACBYTES' => %d," % crypto_secretbox_MACBYTES
print "'crypto_sign_PUBLICKEYBYTES' => %d," % crypto_sign_PUBLICKEYBYTES
print "'crypto_sign_SECRETKEYBYTES' => %d," % crypto_sign_SECRETKEYBYTES
print "'crypto_sign_SEEDBYTES' => %d," % crypto_sign_SEEDBYTES
print "'crypto_sign_BYTES' => %d," % crypto_sign_BYTES
print "'crypto_stream_KEYBYTES' => %d," % crypto_stream_KEYBYTES
print "'crypto_stream_NONCEBYTES' => %d," % crypto_stream_NONCEBYTES
print "'crypto_generichash_BYTES' => %d," % crypto_generichash_BYTES
print "'crypto_scalarmult_curve25519_BYTES' => %d," % crypto_scalarmult_curve25519_BYTES
print "'crypto_scalarmult_BYTES' => %d," % crypto_scalarmult_BYTES
print "'crypto_generichash_BYTES_MAX' => %d," % crypto_generichash_BYTES_MAX

7
bindings/py/test.py Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/local/bin/python
from pypcp import *
sk = Key("tom", "me@there")
sk.dump()