pkarashchenko commented on a change in pull request #5837: URL: https://github.com/apache/incubator-nuttx/pull/5837#discussion_r834502554
########## File path: include/sys/random.h ########## @@ -0,0 +1,79 @@ +/**************************************************************************** + * include/sys/random.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SYS_RANDOM_H +#define __INCLUDE_SYS_RANDOM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stddef.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Flags for getrandom(2) + * + * GRND_NONBLOCK Don't block and return EAGAIN instead + * GRND_RANDOM Open /dev/random instead of /dev/urandom + * GRND_INSECURE Return non-cryptographic random bytes + */ + +#define GRND_NONBLOCK (1 << 0) +#define GRND_RANDOM (1 << 1) +#define GRND_INSECURE (1 << 2) Review comment: I have a question of this flag. I see next code in `/dev/urandom` driver: ``` static ssize_t devurand_read(FAR struct file *filep, FAR char *buffer, size_t len) { #ifdef CONFIG_DEV_URANDOM_RANDOM_POOL if (len > 0) { arc4random_buf(buffer, len); } #else size_t n; uint32_t rnd; n = len; ``` so the question is: Maybe we can follow-up with the change and map `GRND_INSECURE` to `O_BINARY` for example and implement `devurand_read()` is the next way: ``` static ssize_t devurand_read(FAR struct file *filep, FAR char *buffer, size_t len) { #ifdef CONFIG_DEV_URANDOM_RANDOM_POOL if ((filep->f_oflags & O_BINARY) == 0) { if (len > 0) { arc4random_buf(buffer, len); } } else #endif { size_t n; uint32_t rnd; n = len; ... } ``` what do you think? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org