Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
smiley
Posts: 1,468
Registered: ‎07-14-2008
My Device: Z10
Accepted Solution

AESCryptoDemo strength question.

I want to use 256bits AES encryption.

 

In the AESCryptoDemo DRBG.cpp file function

 

DRBG::DRBG(GlobalContext & gc) :
   Crypto("DRBG"), context(gc), rngCtx(NULL) {
   int rc = hu_RngDrbgCreate(HU_DRBG_HASH, 112, false, 0, NULL, NULL, &rngCtx,
context.ctx());
  maybeLog("DRBGCreate", rc);
}

 

To change to 256 bits encryption do I just change 112 to 256?

 

do I also need to change in the UI app

 

QString ApplicationUI::generate() {
DRBG drbg(globalContext);
QByteArray buffer(16, 0);
int rc = drbg.getBytes(buffer);
if (rc != SB_SUCCESS) {
toast(
QString("Could not generate random bytes %1").arg(
SBError::getErrorText(rc)));
return "";
}
return toHex(buffer);
}

 

to

 

QByteArray buffer(32, 0);

 

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: AESCryptoDemo strength question.

What you have suggested pretty much matches what the documentation says will happen:

http://developer.blackberry.com/native/reference/core/com.qnx.doc.crypto.lib_ref/topic/manual/about_...

 

Just to confirm, you are aware that this is just generating a random sequence of bytes?  As I understand it, by changing from 112 to 256, you just make it more likely the created data is random. 

 

"do I also need to change in the UI app"

 

Not as far as I can tell- all changing the length of buffer will do is change how many bytes you get back, that is not related to the security settings for the random number generator. 

Please use plain text.
Developer
smiley
Posts: 1,468
Registered: ‎07-14-2008
My Device: Z10

Re: AESCryptoDemo strength question.


peter_strange wrote:

Just to confirm, you are aware that this is just generating a random sequence of bytes?  As I understand it, by changing from 112 to 256, you just make it more likely the created data is random. 



So what makes the app to use 256bits encryption?

Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: AESCryptoDemo strength question.

Hi,

 

Changing DRBG changes the expected quality of the DRBG.

 

The second part, where you're changing the length is the part that will make AES 256 happen.

 

ie:

  DRBG tweak => goodness of key

  Key size change => AES256...

 

 

--
Rob is no longer associated with BlackBerry.
Please use plain text.
Developer
smiley
Posts: 1,468
Registered: ‎07-14-2008
My Device: Z10

Re: AESCryptoDemo strength question.


robbieDubya wrote:

Hi,

 

Changing DRBG changes the expected quality of the DRBG.

 

The second part, where you're changing the length is the part that will make AES 256 happen.

 

ie:

  DRBG tweak => goodness of key

  Key size change => AES256...

 

 



Does this need changing to 32 size for 256bits?

 

    QByteArray buffer(16, 0);
    int rc = drbg.getBytes(buffer);

 

Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: AESCryptoDemo strength question.

Yes, that is the key. (This is what I was referring to as changing the key size).

--
Rob is no longer associated with BlackBerry.
Please use plain text.
Developer
smiley
Posts: 1,468
Registered: ‎07-14-2008
My Device: Z10

Re: AESCryptoDemo strength question.

[ Edited ]

I have changed the following

 

    int rc = hu_RngDrbgCreate(HU_DRBG_HASH, 256, false, 0, NULL, NULL, &rngCtx,
            context.ctx());

    QByteArray buffer(32, 0);
    int rc = drbg.getBytes(buffer);

and now when I call encrypt I'm getting this error

 

Crypto operation failed. SB_ERR_BAD_IV_LEN (59400)

 

these are the keys size 32 hex encoded

 

Debug: key "8c0fa89b1cd6289175f711ffc6d8a856e4f66b69ddbcf7c660cd5c4ac4225d65"
Debug: iv "ccf48494c11f2982f0b118b665411f768568f5404cce20755c159f9856adf843"

 

 edit: I found the problem.  the iv key size was incorrect as the message indicated. do not use the iv.length() when you encrypyt or decrypt.  use SB_AES_128_BLOCK_BYTES instead.  the AESDemo should be corrected.

Please use plain text.
BlackBerry Development Advisor (Retired)
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: AESCryptoDemo strength question.

[ Edited ]

Oh yes - only the key has to change size - not the IV. (IV must stay at block size).

 

I have a bunch of changes planned for the demo... The community is open... :smileywink:

 

ie: you should use iv.length() - just have to make sure the iv is the correct length. (easy way to lead to memory corruption to NOT be using the length of the buffer you're referring to...)

--
Rob is no longer associated with BlackBerry.
Please use plain text.
Developer
smiley
Posts: 1,468
Registered: ‎07-14-2008
My Device: Z10

Re: AESCryptoDemo strength question.


robbieDubya wrote:

Oh yes - only the key has to change size - not the IV. (IV must stay at block size).

 

I have a bunch of changes planned for the demo... The community is open... :smileywink:

 

ie: you should use iv.length() - just have to make sure the iv is the correct length. (easy way to lead to memory corruption to NOT be using the length of the buffer you're referring to...)


OK. Thanks

Please use plain text.