Add library and makefile sample code
7 files deleted
5 files added
New file |
| | |
| | | /********************************************************************************* |
| | | * Copyright: (C) 2020 LingYun IoT System Studio |
| | | * All rights reserved. |
| | | * |
| | | * Filename: encrypto.c |
| | | * Description: This file |
| | | * |
| | | * Version: 1.0.0(2020年04月04日) |
| | | * Author: Guo Wenxue <guowenxue@gmail.com> |
| | | * ChangeLog: 1, Release initial version on "2020年04月04日 21时02分36秒" |
| | | * |
| | | ********************************************************************************/ |
| | | |
| | | #include <stdio.h> |
| | | #include <string.h> |
| | | |
| | | #include "encrypto.h" |
| | | |
| | | int g_var = 0; |
| | | |
| | | static int test(void) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | int encrypto(char *str, char *ciphertxt, int size) |
| | | { |
| | | int i; |
| | | |
| | | test(); |
| | | |
| | | if(!str || !ciphertxt || size<strlen(str)) |
| | | { |
| | | printf("%s:%d %s(): Invalid input arguments\n", __FILE__, __LINE__, __FUNCTION__); |
| | | return -1; |
| | | } |
| | | |
| | | for(i=0; i<strlen(str); i++) |
| | | { |
| | | ciphertxt[i]=str[i]+1; |
| | | } |
| | | |
| | | |
| | | g_var ++; |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | int decrypto(char *ciphertxt, char *text, int size) |
| | | { |
| | | int i; |
| | | |
| | | if( !ciphertxt || !text || size<strlen(ciphertxt) ) |
| | | { |
| | | printf("%s:%d %s(): Invalid input arguments\n", __FILE__, __LINE__, __FUNCTION__); |
| | | return -1; |
| | | } |
| | | |
| | | for(i=0; i<strlen(ciphertxt); i++) |
| | | { |
| | | text[i]=ciphertxt[i]-1; |
| | | } |
| | | |
| | | return 0; |
| | | } |
New file |
| | |
| | | /******************************************************************************** |
| | | * Copyright: (C) 2020 LingYun IoT System Studio |
| | | * All rights reserved. |
| | | * |
| | | * Filename: encrypto.h |
| | | * Description: This head file |
| | | * |
| | | * Version: 1.0.0(2020年04月04日) |
| | | * Author: Guo Wenxue <guowenxue@gmail.com> |
| | | * ChangeLog: 1, Release initial version on "2020年04月04日 21时13分05秒" |
| | | * |
| | | ********************************************************************************/ |
| | | #ifndef _ENCRYPTO_H_ |
| | | #define _ENCRYPTO_H_ |
| | | |
| | | extern int g_var ; |
| | | |
| | | int encrypto(char *str, char *ciphertxt, int size); |
| | | |
| | | int decrypto(char *ciphertxt, char *text, int size); |
| | | |
| | | |
| | | #endif /* ----- #ifndef _ENCRYPTO_H_ ----- */ |
New file |
| | |
| | | LIBNAME=libencrypto |
| | | |
| | | CC=${CROSSTOOL}gcc |
| | | LD=${CROSSTOOL}ld |
| | | AS=${CROSSTOOL}as |
| | | AR=${CROSSTOOL}ar |
| | | |
| | | all: liba |
| | | @rm -f *.o |
| | | |
| | | libso: |
| | | ${CC} -fPIC -shared *.c -o ${LIBNAME}.so |
| | | |
| | | liba: |
| | | ${CC} -c *.c |
| | | ${AR} -rcs ${LIBNAME}.a *.o |
| | | |
| | | clean: |
| | | rm -f ${LIBNAME}.* |
| | | |
| | | distclean: clean |
| | | rm -f *.o |
New file |
| | |
| | | /********************************************************************************* |
| | | * Copyright: (C) 2020 LingYun IoT System Studio |
| | | * All rights reserved. |
| | | * |
| | | * Filename: main.c |
| | | * Description: This file |
| | | * |
| | | * Version: 1.0.0(2020年04月04日) |
| | | * Author: Guo Wenxue <guowenxue@gmail.com> |
| | | * ChangeLog: 1, Release initial version on "2020年04月04日 20时57分10秒" |
| | | * |
| | | ********************************************************************************/ |
| | | |
| | | #include <stdio.h> |
| | | #include "encrypto.h" |
| | | |
| | | int main (int argc, char *argv[]) |
| | | { |
| | | char *str="hello world"; |
| | | char ciphertxt[128]; |
| | | char text[128]; |
| | | |
| | | encrypto(str, ciphertxt, 128); |
| | | printf("cipher text: %s\r\n", ciphertxt); |
| | | |
| | | decrypto(ciphertxt, text, 128); |
| | | printf("text: %s\r\n", text); |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
New file |
| | |
| | | |
| | | APP_NAME=test |
| | | |
| | | CROSSTOOL?=/opt/rpi/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux- |
| | | CC=${CROSSTOOL}gcc |
| | | LD=${CROSSTOOL}ld |
| | | AS=${CROSSTOOL}as |
| | | AR=${CROSSTOOL}ar |
| | | |
| | | # Compile flags |
| | | CFLAGS=-Wall -Werror |
| | | CFLAGS+=-Iencrypto |
| | | |
| | | # Linker flags |
| | | LDFLAGS=-Lencrypto -lencrypto |
| | | |
| | | |
| | | all: banner libencrypto |
| | | ${CC} ${CFLAGS} main.c -o ${APP_NAME} ${LDFLAGS} |
| | | |
| | | banner: |
| | | @echo "Start to compile ${SRC} by ${CC}" |
| | | |
| | | libencrypto: |
| | | @make CROSSTOOL=${CROSSTOOL} -C encrypto |
| | | |
| | | clean: |
| | | @make clean -C encrypto |
| | | rm -f ${APP_NAME} |
| | | |
| | | distclean: clean |
| | | @make distclean -C encrypto |
| | | rm -f *.o |
| | | |