@@ -39,17 +39,12 @@ bool nRFCrypto_Random::begin(void)
3939{
4040 // skip if already called begin before
4141 if (_begun) return true ;
42- _begun = false ;
42+ _begun = true ;
4343
4444 CRYS_RND_WorkBuff_t* workbuf = (CRYS_RND_WorkBuff_t*) rtos_malloc (sizeof (CRYS_RND_WorkBuff_t));
4545 VERIFY (workbuf);
4646
47- nRFCrypto.enable ();
48-
4947 uint32_t err = CRYS_RndInit (&_state, workbuf);
50-
51- nRFCrypto.disable ();
52-
5348 rtos_free (workbuf);
5449
5550 VERIFY_ERROR (err, false );
@@ -62,30 +57,18 @@ void nRFCrypto_Random::end(void)
6257 if (!_begun) return ;
6358 _begun = false ;
6459
65- nRFCrypto.enable ();
66-
6760 uint32_t err = CRYS_RND_UnInstantiation (&_state);
68-
69- nRFCrypto.disable ();
70-
7161 VERIFY_ERROR (err, );
7262}
7363
74-
7564CRYS_RND_State_t* nRFCrypto_Random::getContext (void )
7665{
7766 return &_state;
7867}
7968
8069bool nRFCrypto_Random::addAdditionalInput (uint8_t * input, uint16_t size)
8170{
82- nRFCrypto.enable ();
83-
84- uint32_t err = CRYS_RND_AddAdditionalInput (&_state, input, size);
85-
86- nRFCrypto.disable ();
87-
88- VERIFY_ERROR (err, false );
71+ VERIFY_ERROR (CRYS_RND_AddAdditionalInput (&_state, input, size), false );
8972 return true ;
9073}
9174
@@ -94,12 +77,7 @@ bool nRFCrypto_Random::reseed(void)
9477 CRYS_RND_WorkBuff_t* workbuf = (CRYS_RND_WorkBuff_t*) rtos_malloc (sizeof (CRYS_RND_WorkBuff_t));
9578 VERIFY (workbuf);
9679
97- nRFCrypto.enable ();
98-
9980 uint32_t err = CRYS_RND_Reseeding (&_state, workbuf);
100-
101- nRFCrypto.disable ();
102-
10381 rtos_free (workbuf);
10482
10583 VERIFY_ERROR (err, false );
@@ -108,24 +86,12 @@ bool nRFCrypto_Random::reseed(void)
10886
10987bool nRFCrypto_Random::generate (uint8_t * buf, uint16_t bufsize)
11088{
111- nRFCrypto.enable ();
112-
113- uint32_t err = CRYS_RND_GenerateVector (&_state, bufsize, buf);
114-
115- nRFCrypto.disable ();
116-
117- VERIFY_ERROR (err, false );
89+ VERIFY_ERROR (CRYS_RND_GenerateVector (&_state, bufsize, buf), false );
11890 return true ;
11991}
12092
12193bool nRFCrypto_Random::generateInRange (uint8_t * buf, uint32_t bitsize, uint8_t * max)
12294{
123- nRFCrypto.enable ();
124-
125- uint32_t err = CRYS_RND_GenerateVectorInRange (&_state, CRYS_RND_GenerateVector, bitsize, max, buf);
126-
127- nRFCrypto.disable ();
128-
129- VERIFY_ERROR (err, false );
95+ VERIFY_ERROR (CRYS_RND_GenerateVectorInRange (&_state, CRYS_RND_GenerateVector, bitsize, max, buf), false );
13096 return true ;
13197}
0 commit comments