Linux Kernel (Android) encryption algorithm Summary (iv)-application calls OpenSSL encryption algorithm

Source: Internet
Author: User

Linux Kernel (Android) encryption algorithm Summary (iii)-Application call Kernel cryptographic algorithm interface

The method of how to invoke interfaces in the kernel is described.

This section is mainly about how to invoke the AES encryption algorithm of the Android C + + application calling OpenSSL.


Crypt_ssl.c

#include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include < aes.h> #include <sys/socket.h> #include <linux/if_alg.h> #include <evp.h> #include <stdio.h > #include <stdlib.h> #ifndef af_alg #define AF_ALG #define SOL_ALG 279#endif#define buf_size 16static voi    D Crypt_ssl (char *in, int inlen, char *out,const char *key, char *iv) {Aes_key akey;    Aes_set_encrypt_key (Key, N, &akey); Aes_cbc_encrypt (in, Out, Inlen, &akey, IV, 1);}    int main (int argc, char **argv) {int i;    Char Out[buf_size] = {0};    Char in[buf_size] = "Single Block MSG";    const char KEY[16] = "x06xa9x21x40x36xb8xa1x5b" "x51x2ex03xd5x34x12x00x06";    Char iv[16] = "x3dxafxbax42x9dx9exb4x30" "xb4x22xdax80x2cx9fxacx41";    if (argc! = 2) {printf ("Usage:compare openssl/compare kernel \ n");        } if (strncmp (argv[1], "OpenSSL", 7) = = 0) {printf ("Encrypt by OPENSSL...N"); Crypt_ssL (in, buf_size, out, key, iv);    } for (i = 0; i < buf_size; i) printf ("0x", (unsigned char) out[i]);    printf ("n");  return 0;}

compile files in Android source code:

Android.mk

Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = myencryptlocal_module_tags: = Optionallocal_src_files : =     Crypt_ssl.clocal_shared_libraries: =     libdl      liblog     libcryptolocal_c_includes: =     external/ Openssl/include/openssl     External/openssl/includeinclude $ (build_executable)

after the compilation is complete ,

ADB push testhash/system/bin/

ADB shell chmod A+x/system/bin/testhash

ADB Shell Testhash

Verify the output results.

Linux Kernel (Android) encryption algorithm Summary (iv)-application calls OpenSSL encryption algorithm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.