anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

validation_XX_SQUARE.c (1480B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020, 2021 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file reducer/validation_XX_SQUARE.c
     18  * @brief anastasis reducer api
     19  * @author Christian Grothoff
     20  * @author Dominik Meister
     21  * @author Dennis Neufeld
     22  */
     23 #include <string.h>
     24 #include <stdbool.h>
     25 #include <stdio.h>
     26 #include <math.h>
     27 
     28 /**
     29  * Function to validate a square number.
     30  *
     31  * @param sq_number square number to validate (input)
     32  * @return true if sq_number is a square, else false
     33  */
     34 bool
     35 XX_SQUARE_check (const char *sq_number);
     36 
     37 /* declaration to fix compiler warning */
     38 bool
     39 XX_SQUARE_check (const char *sq_number)
     40 {
     41   unsigned long long n;
     42   unsigned long long r;
     43   char dummy;
     44 
     45   if (1 != sscanf (sq_number,
     46                    "%llu%c",
     47                    &n,
     48                    &dummy))
     49     return false;
     50   r = sqrt (n);
     51   return (n == r * r);
     52 }