Package list libcryptx-perl / 0f163d3
libtomcrypt update Karel Miko 3 years ago
2 changed file(s) with 16 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
257257 int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
258258 int i;
259259 unsigned int total_len = 0;
260 char number[32], *ptr;
260 char *ptr;
261261 int number_len;
262262 int count = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
263263
264264 /* calculate amount of memory required for the list */
265265 for (i=0; i<count; i++) {
266 total_len += (unsigned int)strlen(_crypt_constants[i].name) + 1;
267 /* the above +1 is for the commas */
268 number_len = snprintf(number, sizeof(number), "%d", _crypt_constants[i].value);
269 if ((number_len < 0) ||
270 ((unsigned int)number_len >= sizeof(number)))
266 number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
267 if (number_len < 0)
271268 return -1;
272 total_len += number_len + 1;
273 /* this last +1 is for newlines (and ending NULL) */
269 total_len += number_len;
274270 }
275271
276272 if (names_list == NULL) {
282278 /* build the names list */
283279 ptr = names_list;
284280 for (i=0; i<count; i++) {
285 strcpy(ptr, _crypt_constants[i].name);
286 ptr += strlen(_crypt_constants[i].name);
287 strcpy(ptr, ",");
288 ptr += 1;
289
290 number_len = snprintf(number, sizeof(number), "%d", _crypt_constants[i].value);
291 strcpy(ptr, number);
281 number_len = snprintf(ptr, total_len, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
282 if (number_len < 0) return -1;
283 if ((unsigned int)number_len > total_len) return -1;
284 total_len -= number_len;
292285 ptr += number_len;
293 strcpy(ptr, "\n");
294 ptr += 1;
295286 }
296287 /* to remove the trailing new-line */
297288 ptr -= 1;
318318 int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
319319 int i;
320320 unsigned int total_len = 0;
321 char number[32], *ptr;
321 char *ptr;
322322 int number_len;
323323 int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
324324
325325 /* calculate amount of memory required for the list */
326326 for (i=0; i<count; i++) {
327 total_len += (unsigned int)strlen(_crypt_sizes[i].name) + 1;
328 /* the above +1 is for the commas */
329 number_len = snprintf(number, sizeof(number), "%u", _crypt_sizes[i].size);
330 if ((number_len < 0) ||
331 ((unsigned int)number_len >= sizeof(number)))
327 number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
328 if (number_len < 0)
332329 return -1;
333 total_len += (unsigned int)strlen(number) + 1;
330 total_len += number_len;
334331 /* this last +1 is for newlines (and ending NULL) */
335332 }
336333
343340 /* build the names list */
344341 ptr = names_list;
345342 for (i=0; i<count; i++) {
346 strcpy(ptr, _crypt_sizes[i].name);
347 ptr += strlen(_crypt_sizes[i].name);
348 strcpy(ptr, ",");
349 ptr += 1;
350
351 number_len = snprintf(number, sizeof(number), "%u", _crypt_sizes[i].size);
352 strcpy(ptr, number);
343 number_len = snprintf(ptr, total_len, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
344 if (number_len < 0) return -1;
345 if ((unsigned int)number_len > total_len) return -1;
346 total_len -= number_len;
353347 ptr += number_len;
354 strcpy(ptr, "\n");
355 ptr += 1;
356348 }
357349 /* to remove the trailing new-line */
358350 ptr -= 1;