आप सॉकेट परिवार AF_ALG के माध्यम से उपयोगकर्ता के अंतरिक्ष से गिरी क्रिप्टो CRC32c
(और अन्य हैश/सिफर कार्यों) का उपयोग कर सकते लिनक्स पर:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
#include <sys/param.h>
#include <string.h>
#include <strings.h>
int
main (int argc, char **argv) {
int sds[2] = { -1, -1 };
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "hash",
.salg_name = "crc32c"
};
if ((sds[0] = socket(AF_ALG, SOCK_SEQPACKET, 0)) == -1)
return -1;
if(bind(sds[0], (struct sockaddr *) &sa, sizeof(sa)) != 0)
return -1;
if((sds[1] = accept(sds[0], NULL, 0)) == -1)
return -1;
char *s = "hello";
size_t n = strlen(s);
if (send(sds[1], s, n, MSG_MORE) != n)
return -1;
int crc32c = 0x00000000;
if(read(sds[1], &crc32c, 4) != 4)
return -1;
printf("%08X\n", crc32c);
return 0;
}
आप फाइल या सॉकेट डेटा आप इसे गति कर सकते हैं hashing रहे हैं कर्नेल से बचने के लिए शून्य-प्रति दृष्टिकोण का उपयोग करना -> उपयोगकर्ता-स्पेस बफर प्रति sendfile
और/या splice
के साथ कॉपी करें।
हैप्पी कोडिंग।
स्रोत
2012-06-22 12:20:16