File tree Expand file tree Collapse file tree 3 files changed +31
-25
lines changed Expand file tree Collapse file tree 3 files changed +31
-25
lines changed Original file line number Diff line number Diff line change 1414*/
1515int register_cipher (const struct ltc_cipher_descriptor * cipher )
1616{
17- int x ;
17+ int x , blank = -1 ;
1818
1919 LTC_ARGCHK (cipher != NULL );
2020
21+ if (cipher -> name == NULL )
22+ return -1 ;
23+
2124 /* is it already registered? */
2225 LTC_MUTEX_LOCK (& ltc_cipher_mutex );
2326 for (x = 0 ; x < TAB_SIZE ; x ++ ) {
2427 if (cipher_descriptor [x ].name != NULL && cipher_descriptor [x ].ID == cipher -> ID ) {
2528 LTC_MUTEX_UNLOCK (& ltc_cipher_mutex );
2629 return x ;
2730 }
31+ if (cipher_descriptor [x ].name == NULL && blank == -1 ) {
32+ blank = x ;
33+ }
2834 }
2935
3036 /* find a blank spot */
31- for (x = 0 ; x < TAB_SIZE ; x ++ ) {
32- if (cipher_descriptor [x ].name == NULL ) {
33- XMEMCPY (& cipher_descriptor [x ], cipher , sizeof (struct ltc_cipher_descriptor ));
34- LTC_MUTEX_UNLOCK (& ltc_cipher_mutex );
35- return x ;
36- }
37+ if (blank != -1 ) {
38+ XMEMCPY (& cipher_descriptor [blank ], cipher , sizeof (struct ltc_cipher_descriptor ));
3739 }
3840
3941 /* no spot */
4042 LTC_MUTEX_UNLOCK (& ltc_cipher_mutex );
41- return -1 ;
43+ return blank ;
4244}
Original file line number Diff line number Diff line change 1414*/
1515int register_hash (const struct ltc_hash_descriptor * hash )
1616{
17- int x ;
17+ int x , blank = -1 ;
1818
1919 LTC_ARGCHK (hash != NULL );
2020
21+ if (hash -> name == NULL )
22+ return -1 ;
23+
2124 /* is it already registered? */
2225 LTC_MUTEX_LOCK (& ltc_hash_mutex );
2326 for (x = 0 ; x < TAB_SIZE ; x ++ ) {
2427 if (XMEMCMP (& hash_descriptor [x ], hash , sizeof (struct ltc_hash_descriptor )) == 0 ) {
2528 LTC_MUTEX_UNLOCK (& ltc_hash_mutex );
2629 return x ;
2730 }
31+ if (hash_descriptor [x ].name == NULL && blank == -1 ) {
32+ blank = x ;
33+ }
2834 }
2935
30- /* find a blank spot */
31- for (x = 0 ; x < TAB_SIZE ; x ++ ) {
32- if (hash_descriptor [x ].name == NULL ) {
33- XMEMCPY (& hash_descriptor [x ], hash , sizeof (struct ltc_hash_descriptor ));
34- LTC_MUTEX_UNLOCK (& ltc_hash_mutex );
35- return x ;
36- }
36+ /* fill in blank spot */
37+ if (blank != -1 ) {
38+ XMEMCPY (& hash_descriptor [blank ], hash , sizeof (struct ltc_hash_descriptor ));
3739 }
3840
3941 /* no spot */
4042 LTC_MUTEX_UNLOCK (& ltc_hash_mutex );
41- return -1 ;
43+ return blank ;
4244}
Original file line number Diff line number Diff line change 1414*/
1515int register_prng (const struct ltc_prng_descriptor * prng )
1616{
17- int x ;
17+ int x , blank = -1 ;
1818
1919 LTC_ARGCHK (prng != NULL );
2020
21+ if (prng -> name == NULL )
22+ return -1 ;
23+
2124 /* is it already registered? */
2225 LTC_MUTEX_LOCK (& ltc_prng_mutex );
2326 for (x = 0 ; x < TAB_SIZE ; x ++ ) {
2427 if (XMEMCMP (& prng_descriptor [x ], prng , sizeof (struct ltc_prng_descriptor )) == 0 ) {
2528 LTC_MUTEX_UNLOCK (& ltc_prng_mutex );
2629 return x ;
2730 }
31+ if (prng_descriptor [x ].name == NULL && blank == -1 ) {
32+ blank = x ;
33+ }
2834 }
2935
3036 /* find a blank spot */
31- for (x = 0 ; x < TAB_SIZE ; x ++ ) {
32- if (prng_descriptor [x ].name == NULL ) {
33- XMEMCPY (& prng_descriptor [x ], prng , sizeof (struct ltc_prng_descriptor ));
34- LTC_MUTEX_UNLOCK (& ltc_prng_mutex );
35- return x ;
36- }
37+ if (blank != -1 ) {
38+ XMEMCPY (& prng_descriptor [blank ], prng , sizeof (struct ltc_prng_descriptor ));
3739 }
3840
3941 /* no spot */
4042 LTC_MUTEX_UNLOCK (& ltc_prng_mutex );
41- return -1 ;
43+ return blank ;
4244}
You can’t perform that action at this time.
0 commit comments