Are there any simple examples on how to use smw security middleware?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Are there any simple examples on how to use smw security middleware?

Jump to solution
1,100 Views
JohnKlug
Senior Contributor I

I attempted to write a program to just do a hash-2 512.  This results in the smw_hash() function calling exit(1).  We also would like to do AES 256 with this library which will require key generation and storage.

Are there any example programs I could look at?  I realize there is a test program, which does work, but it is much more complicated than what I would like to do.

Here is a trace of what I see, just calling smw_hash:

#0  __GI__exit (status=status@entry=1) at /usr/src/debug/glibc/2.39+git/sysdeps/unix/sysv/linux/_exit.c:27
#1  0x0000fffff7d8e0e0 in __run_exit_handlers (status=status@entry=1, listp=0xfffff7ef0660 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:131
#2  0x0000fffff7d8e1f0 in __GI_exit (status=status@entry=1) at exit.c:138
#3  0x0000fffff7f90e88 in config_db_mutex_lock () at /usr/src/debug/smw/git/core/config/database.c:66
#4  0x0000fffff7f916fc in smw_config_select_subsystem (operation_id=OPERATION_ID_HASH, args=0xfffffffff958, subsystem_id=subsystem_id@entry=0xfffffffff94c) at /usr/src/debug/smw/git/core/config/database.c:560
#5  0x0000fffff7f7beb8 in smw_utils_execute_common (operation_id=operation_id@entry=OPERATION_ID_HASH, args=args@entry=0xfffffffff958, subsystem_id=<optimized out>, op_step=op_step@entry=SMW_OP_STEP_ONESHOT, 
    implicit=implicit@entry=false) at /usr/src/debug/smw/git/core/utils/exec.c:38
#6  0x0000fffff7f7bf04 in smw_utils_execute_operation (operation_id=operation_id@entry=OPERATION_ID_HASH, args=args@entry=0xfffffffff958, subsystem_id=<optimized out>)
    at /usr/src/debug/smw/git/core/utils/exec.c:89
#7  0x0000fffff7f88728 in smw_hash (args=args@entry=0xfffffffff9b8) at /usr/src/debug/smw/git/core/crypto/hash.c:115
#8  0x0000aaaaaaaa0a84 in main () at simplehash.c:38

 

This appears to be the cause of the EXIT:
SMW_DBG_ASSERT(ctx);

In my code, I did this prior to calling smw_hash, and it is not getting an error:

    memset(&ctx_args, 0, sizeof(ctx_args));
    ctx_args.subsystem_name = SMW_SUBSYSTEM_NAME_ELE;

    // Allocate context
    smw_result = smw_allocate_context(&ctx_args);
    if (smw_result != SMW_STATUS_OK) {
        printf("Failed to allocate context: %d\n", smw_result);
        return -1;
    }

 I am using IMX91 with  FRDM board, and am building with imx-6.6.36-2.1.0.xml.

Labels (1)
0 Kudos
Reply
1 Solution
1,042 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello,

There is no library to play with this Middleware, and the current just support smw_hash at 64KB. Sorry in this case you can search some solution on the web or wait until next release to see if developers add more space to smw_hash.

Regards

View solution in original post

0 Kudos
Reply
2 Replies
1,078 Views
JohnKlug
Senior Contributor I
I found out that if I called smw_osal_lib_init() first, I could get the smw_hash() to work. However smw_hash() would not work with files much over 64K Bytes. If I want to hash 100MB, how do I do this? I don't think any of the test examples hash large files?
0 Kudos
Reply
1,043 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello,

There is no library to play with this Middleware, and the current just support smw_hash at 64KB. Sorry in this case you can search some solution on the web or wait until next release to see if developers add more space to smw_hash.

Regards

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2075311%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EAre%20there%20any%20simple%20examples%20on%20how%20to%20use%20smw%20security%20middleware%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2075311%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20attempted%20to%20write%20a%20program%20to%20just%20do%20a%20hash-2%20512.%26nbsp%3B%20This%20results%20in%20the%20smw_hash()%20function%20calling%20exit(1).%26nbsp%3B%20We%20also%20would%20like%20to%20do%20AES%20256%20with%20this%20library%20which%20will%20require%20key%20generation%20and%20storage.%3CBR%20%2F%3E%3CBR%20%2F%3EAre%20there%20any%20example%20programs%20I%20could%20look%20at%3F%26nbsp%3B%20I%20realize%20there%20is%20a%20test%20program%2C%20which%20does%20work%2C%20but%20it%20is%20much%20more%20complicated%20than%20what%20I%20would%20like%20to%20do.%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20is%20a%20trace%20of%20what%20I%20see%2C%20just%20calling%20smw_hash%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%230%20%20__GI__exit%20(status%3Dstatus%40entry%3D1)%20at%20%2Fusr%2Fsrc%2Fdebug%2Fglibc%2F2.39%2Bgit%2Fsysdeps%2Funix%2Fsysv%2Flinux%2F_exit.c%3A27%0A%231%20%200x0000fffff7d8e0e0%20in%20__run_exit_handlers%20(status%3Dstatus%40entry%3D1%2C%20listp%3D0xfffff7ef0660%20%26lt%3B__exit_funcs%26gt%3B%2C%20run_list_atexit%3Drun_list_atexit%40entry%3Dtrue%2C%20run_dtors%3Drun_dtors%40entry%3Dtrue)%20at%20exit.c%3A131%0A%232%20%200x0000fffff7d8e1f0%20in%20__GI_exit%20(status%3Dstatus%40entry%3D1)%20at%20exit.c%3A138%0A%233%20%200x0000fffff7f90e88%20in%20config_db_mutex_lock%20()%20at%20%2Fusr%2Fsrc%2Fdebug%2Fsmw%2Fgit%2Fcore%2Fconfig%2Fdatabase.c%3A66%0A%234%20%200x0000fffff7f916fc%20in%20smw_config_select_subsystem%20(operation_id%3DOPERATION_ID_HASH%2C%20args%3D0xfffffffff958%2C%20subsystem_id%3Dsubsystem_id%40entry%3D0xfffffffff94c)%20at%20%2Fusr%2Fsrc%2Fdebug%2Fsmw%2Fgit%2Fcore%2Fconfig%2Fdatabase.c%3A560%0A%235%20%200x0000fffff7f7beb8%20in%20smw_utils_execute_common%20(operation_id%3Doperation_id%40entry%3DOPERATION_ID_HASH%2C%20args%3Dargs%40entry%3D0xfffffffff958%2C%20subsystem_id%3D%3COPTIMIZED%20out%3D%22%22%3E%2C%20op_step%3Dop_step%40entry%3DSMW_OP_STEP_ONESHOT%2C%20%0A%20%20%20%20implicit%3Dimplicit%40entry%3Dfalse)%20at%20%2Fusr%2Fsrc%2Fdebug%2Fsmw%2Fgit%2Fcore%2Futils%2Fexec.c%3A38%0A%236%20%200x0000fffff7f7bf04%20in%20smw_utils_execute_operation%20(operation_id%3Doperation_id%40entry%3DOPERATION_ID_HASH%2C%20args%3Dargs%40entry%3D0xfffffffff958%2C%20subsystem_id%3D%3COPTIMIZED%20out%3D%22%22%3E)%0A%20%20%20%20at%20%2Fusr%2Fsrc%2Fdebug%2Fsmw%2Fgit%2Fcore%2Futils%2Fexec.c%3A89%0A%237%20%200x0000fffff7f88728%20in%20smw_hash%20(args%3Dargs%40entry%3D0xfffffffff9b8)%20at%20%2Fusr%2Fsrc%2Fdebug%2Fsmw%2Fgit%2Fcore%2Fcrypto%2Fhash.c%3A115%0A%238%20%200x0000aaaaaaaa0a84%20in%20main%20()%20at%20simplehash.c%3A38%3C%2FOPTIMIZED%3E%3C%2FOPTIMIZED%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EThis%20appears%20to%20be%20the%20cause%20of%20the%20EXIT%3A%3CBR%20%2F%3ESMW_DBG_ASSERT(ctx)%3B%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20my%20code%2C%20I%20did%20this%20prior%20to%20calling%20smw_hash%2C%20and%20it%20is%20not%20getting%20an%20error%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%20%20%20%20memset(%26amp%3Bctx_args%2C%200%2C%20sizeof(ctx_args))%3B%0A%20%20%20%20ctx_args.subsystem_name%20%3D%20SMW_SUBSYSTEM_NAME_ELE%3B%0A%0A%20%20%20%20%2F%2F%20Allocate%20context%0A%20%20%20%20smw_result%20%3D%20smw_allocate_context(%26amp%3Bctx_args)%3B%0A%20%20%20%20if%20(smw_result%20!%3D%20SMW_STATUS_OK)%20%7B%0A%20%20%20%20%20%20%20%20printf(%22Failed%20to%20allocate%20context%3A%20%25d%5Cn%22%2C%20smw_result)%3B%0A%20%20%20%20%20%20%20%20return%20-1%3B%0A%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3BI%20am%20using%20IMX91%20with%26nbsp%3B%20FRDM%20board%2C%20and%20am%20building%20with%20imx-6.6.36-2.1.0.xml.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2075311%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EFRDM-Training%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2078415%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Are%20there%20any%20simple%20examples%20on%20how%20to%20use%20smw%20security%20middleware%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2078415%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EThere%20is%20no%20library%20to%20play%20with%20this%20Middleware%2C%20and%20the%20current%20just%20support%20smw_hash%20at%2064KB.%20Sorry%20in%20this%20case%20you%20can%20search%20some%20solution%20on%20the%20web%20or%20wait%20until%20next%20release%20to%20see%20if%20developers%20add%20more%20space%20to%20smw_hash.%3C%2FP%3E%0A%3CP%3ERegards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2075447%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Are%20there%20any%20simple%20examples%20on%20how%20to%20use%20smw%20security%20middleware%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2075447%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EI%20found%20out%20that%20if%20I%20called%20smw_osal_lib_init()%20first%2C%20I%20could%20get%20the%20smw_hash()%20to%20work.%20However%20smw_hash()%20would%20not%20work%20with%20files%20much%20over%2064K%20Bytes.%20If%20I%20want%20to%20hash%20100MB%2C%20how%20do%20I%20do%20this%3F%20I%20don't%20think%20any%20of%20the%20test%20examples%20hash%20large%20files%3F%3C%2FLINGO-BODY%3E