  186 |
  187 |             if (MPI_SUCCESS != (mpi_code = MPI_Comm_free_keyval(&key_val)))
  188 |                 HMPI_GOTO_ERROR(FAIL, "MPI_Comm_free_keyval failed", mpi_code)
  189 |         }
  190 |     }
  191 | #endif /*H5_HAVE_PARALLEL*/
  192 |
  193 |     /*
  194 |      * Make sure the package information is updated.
  195 |      */
  196 |     memset(&H5_debug_g, 0, sizeof H5_debug_g);
  197 |     H5_debug_g.pkg[H5_PKG_A].name  = "a";
  198 |     H5_debug_g.pkg[H5_PKG_AC].name = "ac";
  199 |     H5_debug_g.pkg[H5_PKG_B].name  = "b";
  200 |     H5_debug_g.pkg[H5_PKG_D].name  = "d";
  201 |     H5_debug_g.pkg[H5_PKG_E].name  = "e";
  202 |     H5_debug_g.pkg[H5_PKG_F].name  = "f";
  203 |     H5_debug_g.pkg[H5_PKG_G].name  = "g";
  204 |     H5_debug_g.pkg[H5_PKG_HG].name = "hg";
  205 |     H5_debug_g.pkg[H5_PKG_HL].name = "hl";
  206 |     H5_debug_g.pkg[H5_PKG_I].name  = "i";
  207 |     H5_debug_g.pkg[H5_PKG_M].name  = "m";
  208 |     H5_debug_g.pkg[H5_PKG_MF].name = "mf";
  209 |     H5_debug_g.pkg[H5_PKG_MM].name = "mm";
  210 |     H5_debug_g.pkg[H5_PKG_O].name  = "o";
  211 |     H5_debug_g.pkg[H5_PKG_P].name  = "p";
  212 |     H5_debug_g.pkg[H5_PKG_S].name  = "s";
  213 |     H5_debug_g.pkg[H5_PKG_T].name  = "t";
  214 |     H5_debug_g.pkg[H5_PKG_V].name  = "v";
  215 |     H5_debug_g.pkg[H5_PKG_VL].name = "vl";
  216 |     H5_debug_g.pkg[H5_PKG_Z].name  = "z";
  217 |
  218 |     /*
  219 |      * Install atexit() library cleanup routines unless the H5dont_atexit()
  220 |      * has been called.  Once we add something to the atexit() list it stays
  221 |      * there permanently, so we set H5_dont_atexit_g after we add it to prevent
  222 |      * adding it again later if the library is closed and reopened.
  223 |      */
  224 |     if (!H5_dont_atexit_g) {
  225 |
  226 | #ifdef H5_HAVE_THREADSAFE_API
  227 |         /* Clean up thread resources.
  228 |          *
  229 |          * This must be pushed before the library cleanup code so it's
  230 |          * executed in LIFO order (i.e., last).
  231 |          */
  232 |         (void)atexit(H5TS_term_package);
  233 | #endif /* H5_HAVE_THREADSAFE_API */
  234 |
  235 |         /* Normal library termination code */
  236 |         (void)atexit(H5_term_library);
  237 |
  238 |         H5_dont_atexit_g = true;
  239 |     } /* end if */
  240 |
  241 |     /*
  242 |      * Initialize interfaces that use macros of the form "(H5OPEN <var>)", so
  243 |      * that the variable returned through the macros has been initialized.
  244 |      * Also initialize some interfaces that might not be able to initialize
  245 |      * themselves soon enough.
  246 |      *
  247 |      * Interfaces returning variables through a macro: H5E, H5FD, H5O, H5P, H5T
  248 |      *
  249 |      * The link interface needs to be initialized so that the external link
  250 |      *   class is registered.
  251 |      *
  252 |      * The FS module needs to be initialized as a result of the fix for HDFFV-10160:
  253 |      *   It might not be initialized during normal file open.
  254 |      *   When the application does not close the file, routines in the module might
  255 |      *   be called via H5_term_library() when shutting down the file.
  256 |      *
  257 |      * The dataspace interface needs to be initialized so that future IDs for
  258 |      *   dataspaces work.
  259 |      *
  260 |      * The VFD & VOL interfaces need to be initialized before the H5P interface
  261 |      *   so that the default VFD and default VOL connector are ready for the
  262 |      *   default FAPL.
  263 |      *
  264 |      */
  265 |     if (H5E_init() < 0)
  266 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize error interface");
  267 |     if (H5FD_init() < 0)
  268 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize VFL interface");
  269 |     if (H5VL_init_phase1() < 0)
  270 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface");
  271 |     if (H5P_init_phase1() < 0)
  272 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize property list interface");
  273 |     if (H5L_init() < 0)
  274 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize link interface");
  275 |     if (H5O_init() < 0)
  276 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize object interface");
  277 |     if (H5FS_init() < 0)
  278 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize FS interface");
  279 |     if (H5S_init() < 0)
  280 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize dataspace interface");
  281 |     if (H5T_init() < 0)
  282 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize datatype interface");
  283 |
  284 |     /* Finish initializing interfaces that depend on the interfaces above */
  285 |     if (H5P_init_phase2() < 0)
> 286 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize property list interface");
  287 |     if (H5VL_init_phase2() < 0)
  288 |         HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, FAIL, "unable to initialize vol interface");
  289 |
  290 |     /* Debugging? */
  291 |     H5__debug_mask("-all");
  292 |     H5__debug_mask(getenv("HDF5_DEBUG"));
  293 |
  294 | done:
  295 |     FUNC_LEAVE_NOAPI(ret_value)
  296 | } /* end H5_init_library() */
  297 |
  298 | /*-------------------------------------------------------------------------
  299 |  * Function:    H5_term_library
  300 |  *
  301 |  * Purpose:    Terminate interfaces in a well-defined order due to
  302 |  *        dependencies among the interfaces, then terminate
  303 |  *        library-specific data.
  304 |  *
  305 |  * Return:    void
  306 |  *
  307 |  *-------------------------------------------------------------------------
  308 |  */
  309 | void
  310 | H5_term_library(void)
  311 | {
  312 |     int         pending, ntries = 0, n;
  313 |     size_t      at = 0;
  314 |     char        loop[1024];
  315 |     H5E_auto2_t func;
  316 |     H5CX_node_t api_ctx = {{0}, NULL}; /* API context node to push */
  317 |
  318 |     /* Acquire the API lock */
  319 |     H5_API_SETUP_PUBLIC_API_VARS
  320 |     H5_API_LOCK
  321 |
  322 |     /* Don't do anything if the library is already closed */
  323 |     if (!H5_INIT_GLOBAL)
  324 |         goto done;
  325 |
  326 |     /* Indicate that the library is being shut down */
  327 |     H5_TERM_GLOBAL = true;
  328 |
  329 |     /* Push the API context without checking for errors */
  330 |     H5CX_push(&api_ctx);
  331 |
  332 |     /* Check if we should display error output */
  333 |     (void)H5E_get_default_auto_func(&func);
  334 |
  335 |     /* Iterate over the list of 'atclose' callbacks that have been registered */
  336 |     if (H5_atclose_head) {
  337 |         H5_atclose_node_t *curr_atclose; /* Current 'atclose' node */
  338 |
  339 |         /* Iterate over all 'atclose' nodes, making callbacks */
  340 |         curr_atclose = H5_atclose_head;
  341 |         while (curr_atclose) {
  342 |             H5_atclose_node_t *tmp_atclose; /* Temporary pointer to 'atclose' node */
  343 |
  344 |             /* Prepare & restore library for user callback */
  345 |             H5_BEFORE_USER_CB_NOCHECK
  346 |                 {
  347 |                     /* Invoke callback, providing context */
  348 |                     (*curr_atclose->func)(curr_atclose->ctx);
  349 |                 }
  350 |             H5_AFTER_USER_CB_NOCHECK
  351 |
  352 |             /* Advance to next node and free this one */
  353 |             tmp_atclose  = curr_atclose;
  354 |             curr_atclose = curr_atclose->next;
  355 |             H5FL_FREE(H5_atclose_node_t, tmp_atclose);
  356 |         } /* end while */
  357 |
  358 |         /* Reset list head, in case library is re-initialized */
  359 |         H5_atclose_head = NULL;
  360 |     } /* end if */
  361 |
  362 |     /*
  363 |      * Terminate each interface. The termination functions return a positive
  364 |      * value if they do something that might affect some other interface in a
  365 |      * way that would necessitate some cleanup work in the other interface.
  366 |      */
  367 | #define DOWN(F)                                                                                \
  368 |     (((n = H5##F##_term_package()) && (at + 8) < sizeof loop)                                                \
  369 |          ? (sprintf(loop + at, "%s%s", (at ? "," : ""), #F), at += strlen(loop + at), n)                     \
  370 |          : ((n > 0 && (at + 5) < sizeof loop) ? (sprintf(loop + at, "..."), at += strlen(loop + at), n)      \
  371 |                                               : n))
  372 |
  373 |     do {
  374 |         pending = 0;
  375 |
  376 |         /* Try to organize these so the "higher" level components get shut
  377 |          * down before "lower" level components that they might rely on. -QAK
  378 |          */
  379 |
  380 |         /* Close the event sets first, so that all asynchronous operations
  381 |          * complete before anything else attempts to shut down.
  382 |          */
  383 |         pending += DOWN(ES);
  384 |
  385 |         /* Close down the user-facing interfaces, after the event sets */
  386 |         if (pending == 0) {

Reach line at /src/hdf5/src/H5.c:286 (observed count 0).


  785 |                         "attempt to notify cache that ring is unsettled failed");
  786 |
  787 |         /* Check if the free space manager for the file has been initialized */
  788 |         if (!f->shared->fs_man[fs_type] && H5_addr_defined(f->shared->fs_addr[fs_type])) {
  789 |             /* Open the free-space manager */
  790 |             if (H5MF__open_fstype(f, fs_type) < 0)
  791 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTOPENOBJ, HADDR_UNDEF, "can't initialize file free space");
  792 |             assert(f->shared->fs_man[fs_type]);
  793 |         } /* end if */
  794 |
  795 |         /* Search for large enough space in the free space manager */
  796 |         if (f->shared->fs_man[fs_type])
  797 |             if (H5MF__find_sect(f, alloc_type, size, f->shared->fs_man[fs_type], &ret_value) < 0)
  798 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "error locating a node");
  799 |     } /* end if */
  800 |
  801 |     /* If no space is found from the free-space manager, continue further action */
  802 |     if (!H5_addr_defined(ret_value)) {
  803 | #ifdef H5MF_ALLOC_DEBUG_MORE
  804 |         fprintf(stderr, "%s: Check 2.0\n", __func__);
  805 | #endif /* H5MF_ALLOC_DEBUG_MORE */
  806 |         if (f->shared->fs_strategy == H5F_FSPACE_STRATEGY_PAGE) {
  807 |             assert(f->shared->fs_page_size >= H5F_FILE_SPACE_PAGE_SIZE_MIN);
  808 |             if (HADDR_UNDEF == (ret_value = H5MF__alloc_pagefs(f, alloc_type, size)))
  809 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF,
  810 |                             "allocation failed from paged aggregation");
  811 |         }      /* end if */
  812 |         else { /* For non-paged aggregation, continue further action */
  813 |             if (HADDR_UNDEF == (ret_value = H5MF_aggr_vfd_alloc(f, alloc_type, size)))
  814 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "allocation failed from aggr/vfd");
  815 |         } /* end else */
  816 |     }     /* end if */
  817 |     assert(H5_addr_defined(ret_value));
  818 | #ifdef H5MF_ALLOC_DEBUG_MORE
  819 |     fprintf(stderr, "%s: Check 3.0\n", __func__);
  820 | #endif /* H5MF_ALLOC_DEBUG_MORE */
  821 |
  822 | done:
  823 |     /* Reset the ring in the API context */
  824 |     if (orig_ring != H5AC_RING_INV)
  825 |         H5AC_set_ring(orig_ring, NULL);
  826 |
  827 | #ifdef H5MF_ALLOC_DEBUG
  828 |     fprintf(stderr, "%s: Leaving: ret_value = %" PRIuHADDR ", size = %" PRIuHSIZE "\n", __func__, ret_value,
  829 |             size);
  830 | #endif /* H5MF_ALLOC_DEBUG */
  831 | #ifdef H5MF_ALLOC_DEBUG_DUMP
  832 |     H5MF__sects_dump(f, stderr);
  833 | #endif /* H5MF_ALLOC_DEBUG_DUMP */
  834 |
  835 |     FUNC_LEAVE_NOAPI_TAG(ret_value)
  836 | } /* end H5MF_alloc() */
  837 |
  838 | /*-------------------------------------------------------------------------
  839 |  * Function:    H5MF__alloc_pagefs
  840 |  *
  841 |  * Purpose:     Allocate space from either the large or small free-space manager.
  842 |  *              For "large" request:
  843 |  *                  Allocate request from VFD
  844 |  *                  Determine mis-aligned fragment and return the fragment to the
  845 |  *                  appropriate manager
  846 |  *              For "small" request:
  847 |  *                  Allocate a page from the large manager
  848 |  *                  Determine whether space is available from a mis-aligned fragment
  849 |  *                  being returned to the manager
  850 |  *              Return left-over space to the manager after fulfilling request
  851 |  *
  852 |  * Return:      Success:        The file address of new chunk.
  853 |  *              Failure:        HADDR_UNDEF
  854 |  *
  855 |  *-------------------------------------------------------------------------
  856 |  */
  857 | static haddr_t
  858 | H5MF__alloc_pagefs(H5F_t *f, H5FD_mem_t alloc_type, hsize_t size)
  859 | {
  860 |     H5F_mem_page_t       ptype;                     /* Free-space manager type */
  861 |     H5MF_free_section_t *node        = NULL;        /* Free space section pointer */
  862 |     bool    section_merged_or_shrunk = false;       /* Whether free space section was merged or shrunk away */
  863 |     haddr_t ret_value                = HADDR_UNDEF; /* Return value */
  864 |
  865 |     FUNC_ENTER_PACKAGE
  866 |
  867 | #ifdef H5MF_ALLOC_DEBUG
  868 |     fprintf(stderr, "%s: alloc_type = %u, size = %" PRIuHSIZE "\n", __func__, (unsigned)alloc_type, size);
  869 | #endif /* H5MF_ALLOC_DEBUG */
  870 |
  871 |     H5MF__alloc_to_fs_type(f->shared, alloc_type, size, &ptype);
  872 |
  873 |     switch (ptype) {
  874 |         case H5F_MEM_PAGE_GENERIC:
  875 |         case H5F_MEM_PAGE_LARGE_BTREE:
  876 |         case H5F_MEM_PAGE_LARGE_DRAW:
  877 |         case H5F_MEM_PAGE_LARGE_GHEAP:
  878 |         case H5F_MEM_PAGE_LARGE_LHEAP:
  879 |         case H5F_MEM_PAGE_LARGE_OHDR: {
  880 |             haddr_t eoa;           /* EOA for the file */
  881 |             hsize_t frag_size = 0; /* Fragment size */
  882 |
  883 |             /* Get the EOA for the file */
  884 |             if (HADDR_UNDEF == (eoa = H5F_get_eoa(f, alloc_type)))
> 885 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGET, HADDR_UNDEF, "Unable to get eoa");
  886 |             assert(!(eoa % f->shared->fs_page_size));
  887 |
  888 |             H5MF_EOA_MISALIGN(f, (eoa + size), f->shared->fs_page_size, frag_size);
  889 |
  890 |             /* Allocate from VFD */
  891 |             if (HADDR_UNDEF == (ret_value = H5F__alloc(f, alloc_type, size + frag_size, NULL, NULL)))
  892 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't allocate file space");
  893 |
  894 |             /* If there is a mis-aligned fragment at EOA */
  895 |             if (frag_size) {
  896 |
  897 |                 /* Start up the free-space manager */
  898 |                 if (!(f->shared->fs_man[ptype]))
  899 |                     if (H5MF__start_fstype(f, ptype) < 0)
  900 |                         HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF,
  901 |                                     "can't initialize file free space");
  902 |
  903 |                 /* Create free space section for the fragment */
  904 |                 if (NULL == (node = H5MF__sect_new(H5MF_FSPACE_SECT_LARGE, ret_value + size, frag_size)))
  905 |                     HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF,
  906 |                                 "can't initialize free space section");
  907 |
  908 |                 /* Add the fragment to the large free-space manager */
  909 |                 if (H5MF__add_sect(f, alloc_type, f->shared->fs_man[ptype], node, &section_merged_or_shrunk) <
  910 |                     0) {
  911 |                     if (section_merged_or_shrunk)
  912 |                         node = NULL;
  913 |                     HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINSERT, HADDR_UNDEF,
  914 |                                 "can't re-add section to file free space");
  915 |                 }
  916 |
  917 |                 node = NULL;
  918 |             } /* end if */
  919 |         } break;
  920 |
  921 |         case H5F_MEM_PAGE_META:
  922 |         case H5F_MEM_PAGE_DRAW:
  923 |         case H5F_MEM_PAGE_BTREE:
  924 |         case H5F_MEM_PAGE_GHEAP:
  925 |         case H5F_MEM_PAGE_LHEAP:
  926 |         case H5F_MEM_PAGE_OHDR: {
  927 |             haddr_t new_page; /* The address for the new file size page */
  928 |
  929 |             /* Allocate one file space page */
  930 |             if (HADDR_UNDEF == (new_page = H5MF_alloc(f, alloc_type, f->shared->fs_page_size)))
  931 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't allocate file space");
  932 |
  933 |             /* Start up the free-space manager */
  934 |             if (!(f->shared->fs_man[ptype]))
  935 |                 if (H5MF__start_fstype(f, ptype) < 0)
  936 |                     HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "can't initialize file free space");
  937 |             assert(f->shared->fs_man[ptype]);
  938 |
  939 |             if (NULL == (node = H5MF__sect_new(H5MF_FSPACE_SECT_SMALL, (new_page + size),
  940 |                                                (f->shared->fs_page_size - size))))
  941 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "can't initialize free space section");
  942 |
  943 |             /* Add the remaining space in the page to the manager */
  944 |             if (H5MF__add_sect(f, alloc_type, f->shared->fs_man[ptype], node, &section_merged_or_shrunk) <
  945 |                 0) {
  946 |                 if (section_merged_or_shrunk)
  947 |                     node = NULL;
  948 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINSERT, HADDR_UNDEF,
  949 |                             "can't re-add section to file free space");
  950 |             }
  951 |
  952 |             node = NULL;
  953 |
  954 |             /* Insert the new page into the Page Buffer list of new pages so
  955 |                we don't read an empty page from disk */
  956 |             if (f->shared->page_buf != NULL && H5PB_add_new_page(f->shared, alloc_type, new_page) < 0)
  957 |                 HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINSERT, HADDR_UNDEF,
  958 |                             "can't add new page to Page Buffer new page list");
  959 |
  960 |             ret_value = new_page;
  961 |         } break;
  962 |
  963 |         case H5F_MEM_PAGE_NTYPES:
  964 |         case H5F_MEM_PAGE_DEFAULT:
  965 |         default:
  966 |             HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF,
  967 |                         "can't allocate file space: unrecognized type");
  968 |             break;
  969 |     } /* end switch */
  970 |
  971 | done:
  972 | #ifdef H5MF_ALLOC_DEBUG
  973 |     fprintf(stderr, "%s: Leaving: ret_value = %" PRIuHADDR ", size = %" PRIuHSIZE "\n", __func__, ret_value,
  974 |             size);
  975 | #endif /* H5MF_ALLOC_DEBUG */
  976 | #ifdef H5MF_ALLOC_DEBUG_DUMP
  977 |     H5MF__sects_dump(f, stderr);
  978 | #endif /* H5MF_ALLOC_DEBUG_DUMP */
  979 |
  980 |     /* Release section node, if allocated and not added to section list or merged */
  981 |     if (node)
  982 |         if (H5MF__sect_free((H5FS_section_info_t *)node) < 0)
  983 |             HDONE_ERROR(H5E_RESOURCE, H5E_CANTRELEASE, HADDR_UNDEF, "can't free section node");
  984 |
  985 |     FUNC_LEAVE_NOAPI(ret_value)

Reach line at /src/hdf5/src/H5MF.c:885 (observed count 0).


  2206 | {
  2207 |     Q_ASSERT(parent);
  2208 |     Q_ASSERT(list);
  2209 |     for (QObject *obj : parent->children()) {
  2210 |         if (mo.cast(obj) && (name.isNull() || matches_objectName_non_null(obj, name)))
  2211 |             list->append(obj);
  2212 |         if (options & Qt::FindChildrenRecursively)
  2213 |             qt_qFindChildren_helper(obj, name, mo, list, options);
  2214 |     }
  2215 | }
  2216 |
  2217 | #if QT_CONFIG(regularexpression)
  2218 | /*!
  2219 |     \internal
  2220 | */
  2221 | void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re,
  2222 |                              const QMetaObject &mo, QList<void*> *list, Qt::FindChildOptions options)
  2223 | {
  2224 |     Q_ASSERT(parent);
  2225 |     Q_ASSERT(list);
  2226 |     for (QObject *obj : parent->children()) {
  2227 |         if (mo.cast(obj)) {
  2228 |             QRegularExpressionMatch m = re.match(obj->objectName());
  2229 |             if (m.hasMatch())
  2230 |                 list->append(obj);
  2231 |         }
  2232 |         if (options & Qt::FindChildrenRecursively)
  2233 |             qt_qFindChildren_helper(obj, re, mo, list, options);
  2234 |     }
  2235 | }
  2236 | #endif // QT_CONFIG(regularexpression)
  2237 |
  2238 | /*!
  2239 |     \internal
  2240 | */
  2241 | QObject *qt_qFindChild_helper(const QObject *parent, QAnyStringView name, const QMetaObject &mo, Qt::FindChildOptions options)
  2242 | {
  2243 |     Q_ASSERT(parent);
  2244 |     for (QObject *obj : parent->children()) {
  2245 |         if (mo.cast(obj) && (name.isNull() || matches_objectName_non_null(obj, name)))
  2246 |            return obj;
  2247 |     }
  2248 |     if (options & Qt::FindChildrenRecursively) {
  2249 |         for (QObject *child : parent->children()) {
  2250 |             if (QObject *obj = qt_qFindChild_helper(child, name, mo, options))
  2251 |                 return obj;
  2252 |         }
  2253 |     }
  2254 |     return nullptr;
  2255 | }
  2256 |
  2257 | /*!
  2258 |     Makes the object a child of \a parent.
  2259 |
  2260 |     \sa parent(), children()
  2261 | */
  2262 | void QObject::setParent(QObject *parent)
  2263 | {
  2264 |     Q_D(QObject);
  2265 |     Q_ASSERT(!d->isWidget);
  2266 |     d->setParent_helper(parent);
  2267 | }
  2268 |
  2269 | void QObjectPrivate::deleteChildren()
  2270 | {
  2271 |     Q_ASSERT_X(!isDeletingChildren, "QObjectPrivate::deleteChildren()", "isDeletingChildren already set, did this function recurse?");
  2272 |     isDeletingChildren = true;
  2273 |     // delete children objects
  2274 |     // don't use qDeleteAll as the destructor of the child might
  2275 |     // delete siblings
  2276 |     for (int i = 0; i < children.size(); ++i) {
  2277 |         currentChildBeingDeleted = children.at(i);
  2278 |         children[i] = nullptr;
  2279 |         delete currentChildBeingDeleted;
  2280 |     }
  2281 |     children.clear();
  2282 |     currentChildBeingDeleted = nullptr;
  2283 |     isDeletingChildren = false;
  2284 | }
  2285 |
  2286 | void QObjectPrivate::setParent_helper(QObject *o)
  2287 | {
  2288 |     Q_Q(QObject);
  2289 |     Q_ASSERT_X(q != o, Q_FUNC_INFO, "Cannot parent a QObject to itself");
  2290 | #ifdef QT_DEBUG
  2291 |     const auto checkForParentChildLoops = qScopeGuard([&](){
  2292 |         int depth = 0;
  2293 |         auto p = parent;
  2294 |         while (p) {
  2295 |             if (++depth == CheckForParentChildLoopsWarnDepth) {
  2296 |                 qWarning("QObject %p (class: '%s', object name: '%s') may have a loop in its parent-child chain; "
  2297 |                          "this is undefined behavior",
  2298 |                          q, q->metaObject()->className(), qPrintable(q->objectName()));
  2299 |             }
  2300 |             p = p->parent();
  2301 |         }
  2302 |     });
  2303 | #endif
  2304 |
  2305 |     if (o == parent)
> 2306 |         return;
  2307 |
  2308 |     if (parent) {
  2309 |         QObjectPrivate *parentD = parent->d_func();
  2310 |         if (parentD->isDeletingChildren && wasDeleted
  2311 |             && parentD->currentChildBeingDeleted == q) {
  2312 |             // don't do anything since QObjectPrivate::deleteChildren() already
  2313 |             // cleared our entry in parentD->children.
  2314 |         } else {
  2315 |             const qsizetype index = parentD->children.indexOf(q);
  2316 |             if (index < 0) {
  2317 |                 // we're probably recursing into setParent() from a ChildRemoved event, don't do anything
  2318 |             } else if (parentD->isDeletingChildren) {
  2319 |                 parentD->children[index] = nullptr;
  2320 |             } else {
  2321 |                 parentD->children.removeAt(index);
  2322 |                 if (sendChildEvents && parentD->receiveChildEvents) {
  2323 |                     QChildEvent e(QEvent::ChildRemoved, q);
  2324 |                     QCoreApplication::sendEvent(parent, &e);
  2325 |                 }
  2326 |             }
  2327 |         }
  2328 |     }
  2329 |
  2330 |     if (receiveParentEvents) {
  2331 |         Q_ASSERT(!isWidget); // Handled in QWidget
  2332 |         QEvent e(QEvent::ParentAboutToChange);
  2333 |         QCoreApplication::sendEvent(q, &e);
  2334 |     }
  2335 |
  2336 |     parent = o;
  2337 |
  2338 |     if (parent) {
  2339 |         // object hierarchies are constrained to a single thread
  2340 |         if (threadData.loadRelaxed() != parent->d_func()->threadData.loadRelaxed()) {
  2341 |             qWarning("QObject::setParent: Cannot set parent, new parent is in a different thread");
  2342 |             parent = nullptr;
  2343 |             return;
  2344 |         }
  2345 |         parent->d_func()->children.append(q);
  2346 |         if (sendChildEvents && parent->d_func()->receiveChildEvents) {
  2347 |             if (!isWidget) {
  2348 |                 QChildEvent e(QEvent::ChildAdded, q);
  2349 |                 QCoreApplication::sendEvent(parent, &e);
  2350 |             }
  2351 |         }
  2352 |     }
  2353 |
  2354 |     if (receiveParentEvents) {
  2355 |         Q_ASSERT(!isWidget); // Handled in QWidget
  2356 |         QEvent e(QEvent::ParentChange);
  2357 |         QCoreApplication::sendEvent(q, &e);
  2358 |     }
  2359 | }
  2360 |
  2361 | /*!
  2362 |     \fn void QObject::installEventFilter(QObject *filterObj)
  2363 |
  2364 |     Installs an event filter \a filterObj on this object. For example:
  2365 |     \snippet code/src_corelib_kernel_qobject.cpp 14
  2366 |
  2367 |     An event filter is an object that receives all events that are
  2368 |     sent to this object. The filter can either stop the event or
  2369 |     forward it to this object. The event filter \a filterObj receives
  2370 |     events via its eventFilter() function. The eventFilter() function
  2371 |     must return true if the event should be filtered, (i.e. stopped);
  2372 |     otherwise it must return false.
  2373 |
  2374 |     If multiple event filters are installed on a single object, the
  2375 |     filter that was installed last is activated first.
  2376 |
  2377 |     If \a filterObj has already been installed for this object,
  2378 |     this function moves it so it acts as if it was installed last.
  2379 |
  2380 |     Here's a \c KeyPressEater class that eats the key presses of its
  2381 |     monitored objects:
  2382 |
  2383 |     \snippet code/src_corelib_kernel_qobject.cpp 15
  2384 |
  2385 |     And here's how to install it on two widgets:
  2386 |
  2387 |     \snippet code/src_corelib_kernel_qobject.cpp 16
  2388 |
  2389 |     The QShortcut class, for example, uses this technique to intercept
  2390 |     shortcut key presses.
  2391 |
  2392 |     \warning If you delete the receiver object in your eventFilter()
  2393 |     function, be sure to return true. If you return false, Qt sends
  2394 |     the event to the deleted object and the program will crash.
  2395 |
  2396 |     Note that the filtering object must be in the same thread as this
  2397 |     object. If \a filterObj is in a different thread, this function does
  2398 |     nothing. If either \a filterObj or this object are moved to a different
  2399 |     thread after calling this function, the event filter will not be
  2400 |     called until both objects have the same thread affinity again (it
  2401 |     is \e not removed).
  2402 |
  2403 |     \sa removeEventFilter(), eventFilter(), event()
  2404 | */
  2405 |
  2406 | void QObject::installEventFilter(QObject *obj)

Reach line at /src/qtbase/src/corelib/kernel/qobject.cpp:2306 (observed count 0).


    1 | // Copyright (C) 2016 The Qt Company Ltd.
    2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
    3 | // Qt-Security score:significant reason:default
    4 |
    5 | #ifndef QMUTEX_H
    6 | #define QMUTEX_H
    7 |
    8 | #include <QtCore/qglobal.h>
    9 | #include <QtCore/qatomic.h>
   10 | #include <QtCore/qdeadlinetimer.h>
   11 | #include <QtCore/qtsan_impl.h>
   12 |
   13 | #include <chrono>
   14 |
   15 | QT_BEGIN_NAMESPACE
   16 |
   17 | #if QT_CONFIG(thread) || defined(Q_QDOC)
   18 |
   19 | class QMutex;
   20 | class QRecursiveMutex;
   21 | class QMutexPrivate;
   22 |
   23 | class QT6_ONLY(Q_CORE_EXPORT) QBasicMutex
   24 | {
   25 |     Q_DISABLE_COPY_MOVE(QBasicMutex)
   26 | protected:
   27 |     static constexpr bool FutexAlwaysAvailable =
   28 | #if defined(Q_OS_FREEBSD) || defined(Q_OS_LINUX) || defined(Q_OS_WIN) // these platforms use futex
   29 |             true
   30 | #else
   31 |             false
   32 | #endif
   33 |             ;
   34 |
   35 | public:
   36 |     constexpr QBasicMutex()
   37 |         : d_ptr(nullptr)
   38 |     {}
   39 |
   40 |     // BasicLockable concept
   41 |     inline void lock() noexcept(FutexAlwaysAvailable) {
   42 |         QtTsan::mutexPreLock(this, 0u);
   43 |
   44 |         if (!fastTryLock())
>  45 |             lockInternal();
   46 |
   47 |         QtTsan::mutexPostLock(this, 0u, 0);
   48 |     }
   49 |
   50 |     // BasicLockable concept
   51 |     inline void unlock() noexcept {
   52 |         Q_ASSERT(d_ptr.loadRelaxed()); //mutex must be locked
   53 |
   54 |         QtTsan::mutexPreUnlock(this, 0u);
   55 |
   56 |         if constexpr (FutexAlwaysAvailable) {
   57 |             // we always unlock if we have futexes
   58 |             if (QMutexPrivate *d = d_ptr.fetchAndStoreRelease(nullptr); Q_UNLIKELY(d != dummyLocked()))
   59 |                 unlockInternalFutex(d);     // was contended
   60 |         } else {
   61 |             // if we don't have futexes, we can only unlock if not contended
   62 |             if (QMutexPrivate *d; !d_ptr.testAndSetRelease(dummyLocked(), nullptr, d))
   63 |                 unlockInternal(d);          // was contended
   64 |         }
   65 |
   66 |         QtTsan::mutexPostUnlock(this, 0u);
   67 |     }
   68 |
   69 |     bool tryLock() noexcept {
   70 |         unsigned tsanFlags = QtTsan::TryLock;
   71 |         QtTsan::mutexPreLock(this, tsanFlags);
   72 |
   73 |         const bool success = fastTryLock();
   74 |
   75 |         if (!success)
   76 |             tsanFlags |= QtTsan::TryLockFailed;
   77 |         QtTsan::mutexPostLock(this, tsanFlags, 0);
   78 |
   79 |         return success;
   80 |     }
   81 |
   82 |     // Lockable concept
   83 |     bool try_lock() noexcept { return tryLock(); }
   84 |
   85 | private:
   86 |     inline bool fastTryLock() noexcept
   87 |     {
   88 |         if (Q_UNLIKELY(d_ptr.loadRelaxed() != nullptr))
   89 |             return false;
   90 |         return d_ptr.testAndSetAcquire(nullptr, dummyLocked());
   91 |     }
   92 | #if QT_CORE_REMOVED_SINCE(6, 10)
   93 |     inline bool fastTryUnlock() noexcept {
   94 |         return d_ptr.testAndSetRelease(dummyLocked(), nullptr);
   95 |     }
   96 | #endif
   97 |
   98 |     QT7_ONLY(Q_CORE_EXPORT)
   99 |     void lockInternal() noexcept(FutexAlwaysAvailable);
  100 |     QT7_ONLY(Q_CORE_EXPORT)
  101 |     bool lockInternal(QDeadlineTimer timeout) noexcept(FutexAlwaysAvailable);
  102 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
  103 |     bool lockInternal(int timeout) noexcept(FutexAlwaysAvailable);
  104 |     void unlockInternal() noexcept;
  105 | #endif
  106 |     QT7_ONLY(Q_CORE_EXPORT)
  107 |     void unlockInternalFutex(void *d) noexcept;
  108 |     QT7_ONLY(Q_CORE_EXPORT)
  109 |     void unlockInternal(void *d) noexcept;
  110 | #if QT_CORE_REMOVED_SINCE(6, 9)
  111 |     void destroyInternal(QMutexPrivate *d);
  112 | #endif
  113 |     QT7_ONLY(Q_CORE_EXPORT)
  114 |     void destroyInternal(void *d);
  115 |
  116 |     QBasicAtomicPointer<QMutexPrivate> d_ptr;
  117 |     static inline QMutexPrivate *dummyLocked() {
  118 |         return reinterpret_cast<QMutexPrivate *>(quintptr(1));
  119 |     }
  120 |
  121 |     friend class QMutex;
  122 |     friend class QMutexPrivate;
  123 | };
  124 |
  125 | class QT6_ONLY(Q_CORE_EXPORT) QMutex : public QBasicMutex
  126 | {
  127 | public:
  128 |     constexpr QMutex() = default;
  129 |     ~QMutex()
  130 |     {
  131 |         QMutexPrivate *d = d_ptr.loadRelaxed();
  132 |         if (d)
  133 |             destroyInternal(d);
  134 |     }
  135 |
  136 | #ifdef Q_QDOC
  137 |     inline void lock() noexcept(FutexAlwaysAvailable);
  138 |     inline void unlock() noexcept;
  139 |     bool tryLock() noexcept;
  140 | #endif
  141 |
  142 |     // Lockable concept
  143 |     bool try_lock() noexcept { return tryLock(); }
  144 |
  145 |

Reach line at /src/qtbase/src/corelib/thread/qmutex.h:45 (observed count 0).


  119 |     // if the locale is the "C" locale, then we can return the language we found here:
  120 |     if (lang.isEmpty() || lang == "C"_L1 || lang == "POSIX"_L1)
  121 |         return QLocale(lang);
  122 |
  123 |     // ... otherwise, if the first part of LANGUAGE says more than or
  124 |     // contradicts what we have, use that:
  125 |     {
  126 |         QString language = qEnvironmentVariable("LANGUAGE");
  127 |         // We only look at the first entry:
  128 |         if (const auto colon = language.indexOf(u':'); colon >= 0)
  129 |             language.truncate(colon); // unshared QString; this is cheap
  130 |         if (contradicts(language, lang))
  131 |             return QLocale(language);
  132 |     }
  133 |
  134 |     return QLocale(lang);
  135 | }
  136 |
  137 | QVariant QSystemLocale::query(QueryType type, QVariant &&in) const
  138 | {
  139 |     QSystemLocaleData *d = qSystemLocaleData();
  140 |     if (!d)
  141 |         return QVariant();
  142 |
  143 |     if (type == LocaleChanged) {
  144 |         d->readEnvironment();
  145 |         return QVariant();
  146 |     }
  147 |
  148 |     QReadLocker locker(&d->lock);
  149 |
  150 |     const QLocale &lc_numeric = d->lc_numeric;
  151 |     const QLocale &lc_time = d->lc_time;
  152 |     const QLocale &lc_monetary = d->lc_monetary;
  153 |     const QLocale &lc_messages = d->lc_messages;
  154 |
  155 |     switch (type) {
  156 |     case DecimalPoint:
  157 |         return lc_numeric.decimalPoint();
  158 |     case Grouping:
  159 |         return QVariant::fromValue(lc_numeric.d->m_data->groupSizes());
  160 |     case GroupSeparator:
  161 |         return lc_numeric.groupSeparator();
  162 |     case ZeroDigit:
  163 |         return lc_numeric.zeroDigit();
  164 |     case NegativeSign:
  165 |         return lc_numeric.negativeSign();
  166 |     case DateFormatLong:
  167 |         return lc_time.dateFormat(QLocale::LongFormat);
  168 |     case DateFormatShort:
  169 |         return lc_time.dateFormat(QLocale::ShortFormat);
  170 |     case TimeFormatLong:
  171 |         return lc_time.timeFormat(QLocale::LongFormat);
  172 |     case TimeFormatShort:
  173 |         return lc_time.timeFormat(QLocale::ShortFormat);
  174 |     case DayNameLong:
  175 |         return lc_time.dayName(in.toInt(), QLocale::LongFormat);
  176 |     case DayNameShort:
  177 |         return lc_time.dayName(in.toInt(), QLocale::ShortFormat);
  178 |     case DayNameNarrow:
  179 |         return lc_time.dayName(in.toInt(), QLocale::NarrowFormat);
  180 |     case StandaloneDayNameLong:
  181 |         return lc_time.standaloneDayName(in.toInt(), QLocale::LongFormat);
  182 |     case StandaloneDayNameShort:
  183 |         return lc_time.standaloneDayName(in.toInt(), QLocale::ShortFormat);
  184 |     case StandaloneDayNameNarrow:
  185 |         return lc_time.standaloneDayName(in.toInt(), QLocale::NarrowFormat);
  186 |     case MonthNameLong:
  187 |         return lc_time.monthName(in.toInt(), QLocale::LongFormat);
  188 |     case MonthNameShort:
  189 |         return lc_time.monthName(in.toInt(), QLocale::ShortFormat);
  190 |     case MonthNameNarrow:
  191 |         return lc_time.monthName(in.toInt(), QLocale::NarrowFormat);
  192 |     case StandaloneMonthNameLong:
  193 |         return lc_time.standaloneMonthName(in.toInt(), QLocale::LongFormat);
  194 |     case StandaloneMonthNameShort:
  195 |         return lc_time.standaloneMonthName(in.toInt(), QLocale::ShortFormat);
  196 |     case StandaloneMonthNameNarrow:
  197 |         return lc_time.standaloneMonthName(in.toInt(), QLocale::NarrowFormat);
  198 |     case DateToStringLong:
  199 |         return lc_time.toString(in.toDate(), QLocale::LongFormat);
  200 |     case DateToStringShort:
  201 |         return lc_time.toString(in.toDate(), QLocale::ShortFormat);
  202 |     case TimeToStringLong:
  203 |         return lc_time.toString(in.toTime(), QLocale::LongFormat);
  204 |     case TimeToStringShort:
  205 |         return lc_time.toString(in.toTime(), QLocale::ShortFormat);
  206 |     case DateTimeFormatLong:
  207 |         return lc_time.dateTimeFormat(QLocale::LongFormat);
  208 |     case DateTimeFormatShort:
  209 |         return lc_time.dateTimeFormat(QLocale::ShortFormat);
  210 |     case DateTimeToStringLong:
  211 |         return lc_time.toString(in.toDateTime(), QLocale::LongFormat);
  212 |     case DateTimeToStringShort:
  213 |         return lc_time.toString(in.toDateTime(), QLocale::ShortFormat);
  214 |     case PositiveSign:
  215 |         return lc_numeric.positiveSign();
  216 |     case AMText:
  217 |         return lc_time.amText();
  218 |     case PMText:
> 219 |         return lc_time.pmText();
  220 |     case FirstDayOfWeek:
  221 |         return lc_time.firstDayOfWeek();
  222 |     case CurrencySymbol:
  223 |         return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt()));
  224 |     case CurrencyToString: {
  225 |         switch (in.userType()) {
  226 |         case QMetaType::Int:
  227 |             return lc_monetary.toCurrencyString(in.toInt());
  228 |         case QMetaType::UInt:
  229 |             return lc_monetary.toCurrencyString(in.toUInt());
  230 |         case QMetaType::Double:
  231 |             return lc_monetary.toCurrencyString(in.toDouble());
  232 |         case QMetaType::LongLong:
  233 |             return lc_monetary.toCurrencyString(in.toLongLong());
  234 |         case QMetaType::ULongLong:
  235 |             return lc_monetary.toCurrencyString(in.toULongLong());
  236 |         default:
  237 |             break;
  238 |         }
  239 |         return QString();
  240 |     }
  241 |     case MeasurementSystem: {
  242 |         const QString meas_locale = QString::fromLatin1(d->lc_measurement_var);
  243 |         if (meas_locale.compare("Metric"_L1, Qt::CaseInsensitive) == 0)
  244 |             return QLocale::MetricSystem;
  245 |         if (meas_locale.compare("Other"_L1, Qt::CaseInsensitive) == 0)
  246 |             return QLocale::MetricSystem;
  247 |         return QVariant((int)QLocale(meas_locale).measurementSystem());
  248 |     }
  249 |     case Collation:
  250 |         return QString::fromLatin1(d->lc_collate_var);
  251 |     case UILanguages: {
  252 |         if (!d->uiLanguages.isEmpty())
  253 |             return d->uiLanguages;
  254 |         QString languages = QString::fromLatin1(qgetenv("LANGUAGE"));
  255 |         QStringList lst;
  256 |         if (languages.isEmpty())
  257 |             lst.append(QString::fromLatin1(d->lc_messages_var));
  258 |         else
  259 |             lst = languages.split(u':');
  260 |
  261 |         for (const QString &e : std::as_const(lst)) {
  262 |             QStringView language, script, territory;
  263 |             if (qt_splitLocaleName(e, &language, &script, &territory)) {
  264 |                 QString joined = language.isEmpty() ? u"und"_s : language.toString();
  265 |                 if (!script.isEmpty())
  266 |                     joined += u'-' + script;
  267 |                 if (!territory.isEmpty())
  268 |                     joined += u'-' + territory;
  269 |                 d->uiLanguages.append(joined);
  270 |             }
  271 |         }
  272 |         return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages);
  273 |     }
  274 |     case StringToStandardQuotation:
  275 |         return lc_messages.quoteString(qvariant_cast<QStringView>(std::move(in)));
  276 |     case StringToAlternateQuotation:
  277 |         return lc_messages.quoteString(qvariant_cast<QStringView>(std::move(in)),
  278 |                                        QLocale::AlternateQuotation);
  279 |     case ListToSeparatedString:
  280 |         return lc_messages.createSeparatedList(in.toStringList());
  281 |     case LocaleChanged:
  282 |         Q_UNREACHABLE(); // handled before the switch
  283 |     case LanguageId:
  284 |     case TerritoryId:
  285 |     case Weekdays:
  286 |     case ScriptId:
  287 |     case NativeLanguageName:
  288 |     case NativeTerritoryName:
  289 |         break;
  290 |     }
  291 |     return QVariant();
  292 | }
  293 | #endif // QT_NO_SYSTEMLOCALE
  294 |
  295 | QT_END_NAMESPACE

Reach line at /src/qtbase/src/corelib/text/qlocale_unix.cpp:219 (observed count 0).


  1393 |         list.reserve(plist.size());
  1394 |         for (const QTimeZonePrivate::Data &pdata : plist)
  1395 |             list.append(QTimeZonePrivate::toOffsetData(pdata));
  1396 |     }
  1397 |     return list;
  1398 | }
  1399 |
  1400 | // Static methods
  1401 |
  1402 | /*!
  1403 |     Returns the current system time zone IANA ID.
  1404 |
  1405 |     Equivalent to calling systemTimeZone().id(), but may bypass some computation
  1406 |     to obtain it. Constructing a QTimeZone from the returned byte array will
  1407 |     produce the same result as systemTimeZone().
  1408 |
  1409 |     If the backend is unable to determine the correct system zone, the result is
  1410 |     empty. In this case, systemTimeZone().isValid() is false and a warning is
  1411 |     output if either this method of systemTimeZone() is called.
  1412 |
  1413 |     If the backend is able to determine the correct system zone but not its
  1414 |     name, an empty byte array is returned. For example, on Windows, the system
  1415 |     native ID is converted to an IANA ID - if the system ID isn't known to the
  1416 |     internal translation code, the result shall be empty. In this case,
  1417 |     systemTimeZone().isValid() shall be true.
  1418 |
  1419 |     This method is only available when feature \c timezone is enabled.
  1420 |
  1421 |     \note Prior to Qt 6.7, when the result could not be determined, the
  1422 |     misleading result "UTC" was returned.
  1423 |
  1424 |     \sa systemTimeZone()
  1425 | */
  1426 |
  1427 | QByteArray QTimeZone::systemTimeZoneId()
  1428 | {
  1429 |     QByteArray sys = global_tz->backend->systemTimeZoneId();
  1430 |     if (!sys.isEmpty())
  1431 |         return sys;
  1432 |     // The system zone, despite the empty ID, may know its real ID anyway:
  1433 |     return global_tz->backend->id();
  1434 | }
  1435 |
  1436 | /*!
  1437 |     \since 5.5
  1438 |
  1439 |     Returns a QTimeZone object that describes local system time.
  1440 |
  1441 |     This method is only available when feature \c timezone is enabled. The
  1442 |     returned instance is usually equivalent to the lightweight time
  1443 |     representation \c {QTimeZone(QTimeZone::LocalTime)}, albeit implemented as a
  1444 |     time zone.
  1445 |
  1446 |     The returned object will not change to reflect any subsequent change to the
  1447 |     system time zone. It represents the local time that was in effect when
  1448 |     asBackendZone() was called. On misconfigured systems, such as those that
  1449 |     lack the timezone data relied on by the backend for which Qt was compiled,
  1450 |     it may be invalid. In such a case, a warning is output.
  1451 |
  1452 |     \sa utc(), Initialization, asBackendZone(), systemTimeZoneId()
  1453 | */
  1454 | QTimeZone QTimeZone::systemTimeZone()
  1455 | {
  1456 |     // Short-cut constructor's handling of empty ID:
  1457 |     const QByteArray sysId = global_tz->backend->systemTimeZoneId();
  1458 |     const auto sys = sysId.isEmpty() ? QTimeZone(global_tz->backend) : QTimeZone(sysId);
  1459 |     if (!sys.isValid()) {
  1460 |         static bool neverWarned = true;
  1461 |         if (neverWarned) {
  1462 |             // Racey but, at worst, merely repeats the warning.
  1463 |             neverWarned = false;
  1464 |             qWarning("Unable to determine system time zone: "
  1465 |                      "please check your system configuration.");
  1466 |         }
  1467 |     }
  1468 |     return sys;
  1469 | }
  1470 |
  1471 | /*!
  1472 |     \fn QTimeZone QTimeZone::utc()
  1473 |     \since 5.5
  1474 |     Returns a QTimeZone object that describes UTC as a time zone.
  1475 |
  1476 |     This method is only available when feature \c timezone is enabled. It is
  1477 |     equivalent to passing 0 to QTimeZone(int offsetSeconds) and to the
  1478 |     lightweight time representation QTimeZone(QTimeZone::UTC), albeit
  1479 |     implemented as a time zone, unlike the latter.
  1480 |
  1481 |     \sa systemTimeZone(), Initialization, asBackendZone()
  1482 | */
  1483 | QTimeZone QTimeZonePrivate::utcQTimeZone()
  1484 | {
  1485 |     return QTimeZone(*new QUtcTimeZonePrivate());
  1486 | }
  1487 |
  1488 | Q_GLOBAL_STATIC(QTimeZone, utcTimeZone, QTimeZonePrivate::utcQTimeZone());
  1489 |
  1490 | QTimeZone QTimeZone::utc()
  1491 | {
  1492 |     if (Q_UNLIKELY(utcTimeZone.isDestroyed()))
> 1493 |         return QTimeZonePrivate::utcQTimeZone(); // create a new, unshared one
  1494 |     return *utcTimeZone; // take a shallow copy
  1495 | }
  1496 |
  1497 | /*!
  1498 |     Returns \c true if a given time zone \a ianaId is available on this system.
  1499 |
  1500 |     This may be true for some texts that are not in fact IANA IDs, notably
  1501 |     UTC-offset IDs, and known aliases for supported IANA IDs that are not listed
  1502 |     in \l availableTimeZoneIds().
  1503 |
  1504 |     This method is only available when feature \c timezone is enabled.
  1505 |
  1506 |     \sa availableTimeZoneIds(), hasAlternativeName()
  1507 | */
  1508 |
  1509 | bool QTimeZone::isTimeZoneIdAvailable(QByteArrayView ianaId)
  1510 | {
  1511 | #if defined(Q_OS_UNIX) && !(QT_CONFIG(timezone_tzdb) || defined(Q_OS_DARWIN) \
  1512 |                             || defined(Q_OS_ANDROID) || defined(Q_OS_VXWORKS))
  1513 |     // Keep #if-ery consistent with selection of QTzTimeZonePrivate in
  1514 |     // newBackendTimeZone(). Skip the pre-check, as the TZ backend accepts POSIX
  1515 |     // zone IDs, which need not be valid IANA IDs. See also QTBUG-112006.
  1516 | #else
  1517 |     // isValidId is not strictly required, but faster to weed out invalid
  1518 |     // IDs as availableTimeZoneIds() may be slow
  1519 |     if (!QTimeZonePrivate::isValidId(ianaId))
  1520 |         return false;
  1521 | #endif
  1522 |     if (QUtcTimeZonePrivate().isTimeZoneIdAvailable(ianaId)
  1523 |         || QUtcTimeZonePrivate::offsetFromUtcString(ianaId) != QTimeZonePrivate::invalidSeconds()
  1524 |         || global_tz->backend->isTimeZoneIdAvailable(ianaId)) {
  1525 |         return true;
  1526 |     }
  1527 |     if (const auto name = QTimeZonePrivate::aliasToIana(ianaId); !name.isEmpty()) {
  1528 |         return QUtcTimeZonePrivate().isTimeZoneIdAvailable(name)
  1529 |             || global_tz->backend->isTimeZoneIdAvailable(name);
  1530 |     }
  1531 |
  1532 |     QByteArrayView known = global_tz->backend->availableAlias(ianaId);
  1533 |     return !known.isEmpty();
  1534 | }
  1535 |
  1536 | [[maybe_unused]] static bool isUniqueSorted(const QList<QByteArray> &seq)
  1537 | {
  1538 |     // Since [..., b, a, ...] isn't unique-sorted if a <= b, at least the
  1539 |     // suggested implementations of is_sorted() and is_sorted_until() imply a
  1540 |     // non-unique sorted list will fail is_sorted() with <= comparison.
  1541 |     return std::is_sorted(seq.begin(), seq.end(), std::less_equal<QByteArray>());
  1542 | }
  1543 |
  1544 | static QList<QByteArray> set_union(const QList<QByteArray> &l1, const QList<QByteArray> &l2)
  1545 | {
  1546 |     Q_ASSERT(isUniqueSorted(l1));
  1547 |     Q_ASSERT(isUniqueSorted(l2));
  1548 |     QList<QByteArray> result;
  1549 |     result.reserve(l1.size() + l2.size());
  1550 |     std::set_union(l1.begin(), l1.end(),
  1551 |                    l2.begin(), l2.end(),
  1552 |                    std::back_inserter(result));
  1553 |     return result;
  1554 | }
  1555 |
  1556 | /*!
  1557 |     Returns a list of available time zone IDs on this system.
  1558 |
  1559 |     This includes an IANA ID for each zone supported by the system timezone
  1560 |     information source, plus some aliases of these and a limited set of
  1561 |     commonly-used UTC-offset IDs.
  1562 |
  1563 |     The QTimeZone constructor will also accept some UTC-offset IDs that are not
  1564 |     in the list returned - it would be impractical to list all possible
  1565 |     UTC-offset IDs. It also accepts known aliases for supported IANA IDs, some
  1566 |     of which may not appear in this list. Such IDs are also accepted by
  1567 |     isTimeZoneIdAvailable().
  1568 |
  1569 |     Where the Unicode Consortium's Common Locale Data Repository (CLDR) regards
  1570 |     a supported IANA ID as an alias for its stable name for the zone, this
  1571 |     stable name for the zone is also included in the list (even though it may be
  1572 |     out of date), both for stability and as cross-platform common ground where
  1573 |     different system timezone information sources use different aliases for the
  1574 |     same zone.
  1575 |
  1576 |     This method is only available when feature \c timezone is enabled.
  1577 |
  1578 |     \sa isTimeZoneIdAvailable(), hasAlternativeName()
  1579 | */
  1580 |
  1581 | QList<QByteArray> QTimeZone::availableTimeZoneIds()
  1582 | {
  1583 |     // Backends MUST implement availableTimeZoneIds().
  1584 |     // The return from each backend MUST be sorted and unique.
  1585 |     return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(),
  1586 |                      global_tz->backend->availableTimeZoneIds());
  1587 | }
  1588 |
  1589 | /*!
  1590 |     Returns a list of all available IANA time zone IDs for a given \a territory.
  1591 |
  1592 |     As a special case, a \a territory of \l {QLocale::} {AnyTerritory} selects
  1593 |     those time zones that have a non-territorial association, such as UTC, while

Reach line at /src/qtbase/src/corelib/time/qtimezone.cpp:1493 (observed count 0).


  2876 |     // Do the conversion in a year with the same days of the week, so DST
  2877 |     // dates might be right, and adjust by the number of days that was off:
  2878 |     const qint64 jd = msecsToJulianDay(utcMSecs);
  2879 |     const auto ymd = QGregorianCalendar::partsFromJulian(jd);
  2880 |     qint64 diffMillis, fakeUtc;
  2881 |     const auto fakeJd = QGregorianCalendar::julianFromParts(systemTimeYearMatching(ymd.year),
  2882 |                                                             ymd.month, ymd.day);
  2883 |     if (Q_UNLIKELY(!fakeJd
  2884 |                    || qMulOverflow(jd - *fakeJd, std::integral_constant<qint64, MSECS_PER_DAY>(),
  2885 |                                    &diffMillis)
  2886 |                    || qSubOverflow(utcMSecs, diffMillis, &fakeUtc))) {
  2887 |         return result;
  2888 |     }
  2889 |
  2890 |     result = QLocalTime::utcToLocal(fakeUtc);
  2891 |     // Now correct result.when for the use of the fake date:
  2892 |     if (!result.valid || qAddOverflow(result.when, diffMillis, &result.when)) {
  2893 |         // If utcToLocal() failed, its return has the fake when; restore utcMSecs.
  2894 |         // Fail on overflow, but preserve offset and DST-ness.
  2895 |         result.when = utcMSecs;
  2896 |         result.valid = false;
  2897 |     }
  2898 |     return result;
  2899 | }
  2900 |
  2901 | static auto millisToWithinRange(qint64 millis)
  2902 | {
  2903 |     struct R {
  2904 |         qint64 shifted = 0;
  2905 |         bool good = false;
  2906 |     } result;
  2907 |     qint64 jd = msecsToJulianDay(millis);
  2908 |     auto ymd = QGregorianCalendar::partsFromJulian(jd);
  2909 |     const auto fakeJd = QGregorianCalendar::julianFromParts(systemTimeYearMatching(ymd.year),
  2910 |                                                             ymd.month, ymd.day);
  2911 |     result.good = fakeJd && !daysAndMillisOverflow(*fakeJd - jd, millis, &result.shifted);
  2912 |     return result;
  2913 | }
  2914 |
  2915 | /*!
  2916 |     \internal
  2917 |     \enum QDateTimePrivate::TransitionOption
  2918 |
  2919 |     This enumeration is used to resolve datetime combinations which fall in \l
  2920 |     {Timezone transitions}. The transition is described as a "gap" if there are
  2921 |     time representations skipped over by the zone, as is common in the "spring
  2922 |     forward" transitions in many zones on entering daylight-saving time. The
  2923 |     transition is described as a "fold" if there are time representations
  2924 |     repeated in the zone, as in a "fall back" transition out of daylight-saving
  2925 |     time.
  2926 |
  2927 |     When the options specified do not determine a resolution for a datetime, it
  2928 |     is marked invalid.
  2929 |
  2930 |     The prepared option sets above are in fact composed from low-level atomic
  2931 |     options. For each of gap and fold you can chose between two candidate times,
  2932 |     one before or after the transition, based on the time requested; or you can
  2933 |     pick the moment of transition, or the start or end of the transition
  2934 |     interval. For a gap, the start and end of the interval are the moment of the
  2935 |     transition, but for a repeated interval the start of the first pass is the
  2936 |     start of the transition interval, the end of the second pass is the end of
  2937 |     the transition interval and the moment of the transition itself is both the
  2938 |     end of the first pass and the start of the second.
  2939 |
  2940 |     \value GapUseBefore For a time in a gap, use a time before the transition,
  2941 |                         as if stepping back from a later time.
  2942 |     \value GapUseAfter For a time in a gap, use a time after the transition, as
  2943 |                        if stepping forward from an earlier time.
  2944 |     \value FoldUseBefore For a repeated time, use the first candidate, which is
  2945 |                          before the transition.
  2946 |     \value FoldUseAfter For a repeated time, use the second candidate, which is
  2947 |                         after the transition.
  2948 |     \value FlipForReverseDst For "reversed" DST, this reverses the preceding
  2949 |                              four options (see below).
  2950 |
  2951 |     The last has no effect unless the "daylight-saving" time side of the
  2952 |     transition is known to have a lower offset from UTC than the standard time
  2953 |     side. (This is the "reversed" DST case of \l {Timezone transitions}.)  In
  2954 |     that case, if other options would select a time after the transition, a time
  2955 |     before is used instead, and vice versa. This effectively turns a preference
  2956 |     for the side with lower offset into a preference for the side that is
  2957 |     officially standard time, even if it has higher offset; and conversely a
  2958 |     preference for higher offset into a preference for daylight-saving time,
  2959 |     even if it has a lower offset. This option has no effect on a resolution
  2960 |     that selects the moment of transition or the start or end of the transition
  2961 |     interval.
  2962 |
  2963 |     The result of combining more than one of the \c GapUse* options is
  2964 |     undefined; likewise for the \c FoldUse*. Each of QDateTime's
  2965 |     TransitionResolution values, aside from Reject, maps to a combination that
  2966 |     incorporates one from each of these sets.
  2967 | */
  2968 |
  2969 | constexpr static QDateTimePrivate::TransitionOptions
  2970 | toTransitionOptions(QDateTime::TransitionResolution res)
  2971 | {
  2972 |     switch (res) {
  2973 |     case QDateTime::TransitionResolution::RelativeToBefore:
  2974 |         return QDateTimePrivate::GapUseAfter | QDateTimePrivate::FoldUseBefore;
  2975 |     case QDateTime::TransitionResolution::RelativeToAfter:
> 2976 |         return QDateTimePrivate::GapUseBefore | QDateTimePrivate::FoldUseAfter;
  2977 |     case QDateTime::TransitionResolution::PreferBefore:
  2978 |         return QDateTimePrivate::GapUseBefore | QDateTimePrivate::FoldUseBefore;
  2979 |     case QDateTime::TransitionResolution::PreferAfter:
  2980 |         return QDateTimePrivate::GapUseAfter | QDateTimePrivate::FoldUseAfter;
  2981 |     case QDateTime::TransitionResolution::PreferStandard:
  2982 |         return QDateTimePrivate::GapUseBefore
  2983 |             | QDateTimePrivate::FoldUseAfter
  2984 |             | QDateTimePrivate::FlipForReverseDst;
  2985 |     case QDateTime::TransitionResolution::PreferDaylightSaving:
  2986 |         return QDateTimePrivate::GapUseAfter
  2987 |             | QDateTimePrivate::FoldUseBefore
  2988 |             | QDateTimePrivate::FlipForReverseDst;
  2989 |     case QDateTime::TransitionResolution::Reject: break;
  2990 |     }
  2991 |     return {};
  2992 | }
  2993 |
  2994 | constexpr static QDateTimePrivate::TransitionOptions
  2995 | toTransitionOptions(QDateTimePrivate::DaylightStatus dst)
  2996 | {
  2997 |     return toTransitionOptions(dst == QDateTimePrivate::DaylightTime
  2998 |                                ? QDateTime::TransitionResolution::PreferDaylightSaving
  2999 |                                : QDateTime::TransitionResolution::PreferStandard);
  3000 | }
  3001 |
  3002 | QString QDateTimePrivate::localNameAtMillis(qint64 millis, DaylightStatus dst)
  3003 | {
  3004 |     const QDateTimePrivate::TransitionOptions resolve = toTransitionOptions(dst);
  3005 |     QString abbreviation;
  3006 |     if (millisInSystemRange(millis, MSECS_PER_DAY)) {
  3007 |         abbreviation = QLocalTime::localTimeAbbbreviationAt(millis, resolve);
  3008 |         if (!abbreviation.isEmpty())
  3009 |             return abbreviation;
  3010 |     }
  3011 |
  3012 |     // Otherwise, outside the system range.
  3013 | #if QT_CONFIG(timezone)
  3014 |     // Use the system zone:
  3015 |     const auto sys = QTimeZone::systemTimeZone();
  3016 |     if (sys.isValid()) {
  3017 |         ZoneState state = zoneStateAtMillis(sys, millis, resolve);
  3018 |         if (state.valid)
  3019 |             return sys.d->abbreviation(state.when - state.offset * MSECS_PER_SEC);
  3020 |     }
  3021 | #endif // timezone
  3022 |
  3023 |     // Kludge
  3024 |     // Use a time in the system range with the same day-of-week pattern to its year:
  3025 |     auto fake = millisToWithinRange(millis);
  3026 |     if (Q_LIKELY(fake.good))
  3027 |         return QLocalTime::localTimeAbbbreviationAt(fake.shifted, resolve);
  3028 |
  3029 |     // Overflow, apparently.
  3030 |     return {};
  3031 | }
  3032 |
  3033 | // Determine the offset from UTC at the given local time as millis.
  3034 | QDateTimePrivate::ZoneState QDateTimePrivate::localStateAtMillis(
  3035 |     qint64 millis, QDateTimePrivate::TransitionOptions resolve)
  3036 | {
  3037 |     // First, if millis is within a day of the viable range, try mktime() in
  3038 |     // case it does fall in the range and gets useful information:
  3039 |     if (millisInSystemRange(millis, MSECS_PER_DAY)) {
  3040 |         auto result = QLocalTime::mapLocalTime(millis, resolve);
  3041 |         if (result.valid)
  3042 |             return result;
  3043 |     }
  3044 |
  3045 |     // Otherwise, outside the system range.
  3046 | #if QT_CONFIG(timezone)
  3047 |     // Use the system zone:
  3048 |     const auto sys = QTimeZone::systemTimeZone();
  3049 |     if (sys.isValid())
  3050 |         return zoneStateAtMillis(sys, millis, resolve);
  3051 | #endif // timezone
  3052 |
  3053 |     // Kludge
  3054 |     // Use a time in the system range with the same day-of-week pattern to its year:
  3055 |     auto fake = millisToWithinRange(millis);
  3056 |     if (Q_LIKELY(fake.good)) {
  3057 |         auto result = QLocalTime::mapLocalTime(fake.shifted, resolve);
  3058 |         if (result.valid) {
  3059 |             qint64 adjusted;
  3060 |             if (Q_UNLIKELY(qAddOverflow(result.when, millis - fake.shifted, &adjusted))) {
  3061 |                 using Bound = std::numeric_limits<qint64>;
  3062 |                 adjusted = millis < fake.shifted ? Bound::min() : Bound::max();
  3063 |             }
  3064 |             result.when = adjusted;
  3065 |         } else {
  3066 |             result.when = millis;
  3067 |         }
  3068 |         return result;
  3069 |     }
  3070 |     // Overflow, apparently.
  3071 |     return {millis};
  3072 | }
  3073 |
  3074 | #if QT_CONFIG(timezone)
  3075 | // For a TimeZone and a time expressed in zone msecs encoding, compute the
  3076 | // actual DST-ness and offset, adjusting the time if needed to escape a

Reach line at /src/qtbase/src/corelib/time/qdatetime.cpp:2976 (observed count 0).


  172 | 	uint64_t magic;
  173 | 	OQS_SHA3_shake128_inc_ctx ctx;
  174 | } Keccak_HashInstance;
  175 | #define XOF_CTX_X4_INIT_MAGIC 0xf11dbabebadf999dULL
  176 | typedef struct {
  177 | 	uint64_t magic;
  178 | 	OQS_SHA3_shake128_x4_inc_ctx ctx;
  179 | } Keccak_HashInstancetimes4;
  180 | #define __XOF_Init OQS_SHA3_shake128_inc_init
  181 | #define __XOF_Update OQS_SHA3_shake128_inc_absorb
  182 | #define __XOF_Final OQS_SHA3_shake128_inc_finalize
  183 | #define __XOF_Squeeze OQS_SHA3_shake128_inc_squeeze
  184 | #define __XOF_Release OQS_SHA3_shake128_inc_ctx_release
  185 | #define __XOF_Reset OQS_SHA3_shake128_inc_ctx_reset
  186 | #define __XOF_Init_x4 OQS_SHA3_shake128_x4_inc_init
  187 | #define __XOF_Update_x4 OQS_SHA3_shake128_x4_inc_absorb
  188 | #define __XOF_Final_x4 OQS_SHA3_shake128_x4_inc_finalize
  189 | #define __XOF_Squeeze_x4 OQS_SHA3_shake128_x4_inc_squeeze
  190 | #define __XOF_Release_x4 OQS_SHA3_shake128_x4_inc_ctx_release
  191 | #define __XOF_Reset_x4 OQS_SHA3_shake128_x4_inc_ctx_reset
  192 | /* === 192 bits security === */
  193 | #elif MQOM2_PARAM_SECURITY == 192
  194 | #define XOF_CTX_INIT_MAGIC 0xf00dbabebadfeeedULL
  195 | typedef struct {
  196 | 	uint64_t magic;
  197 | 	OQS_SHA3_shake256_inc_ctx ctx;
  198 | } Keccak_HashInstance;
  199 | #define XOF_CTX_X4_INIT_MAGIC 0xf11dbabebadf999dULL
  200 | typedef struct {
  201 | 	uint64_t magic;
  202 | 	OQS_SHA3_shake256_x4_inc_ctx ctx;
  203 | } Keccak_HashInstancetimes4;
  204 | #define __XOF_Init OQS_SHA3_shake256_inc_init
  205 | #define __XOF_Update OQS_SHA3_shake256_inc_absorb
  206 | #define __XOF_Final OQS_SHA3_shake256_inc_finalize
  207 | #define __XOF_Squeeze OQS_SHA3_shake256_inc_squeeze
  208 | #define __XOF_Release OQS_SHA3_shake256_inc_ctx_release
  209 | #define __XOF_Reset OQS_SHA3_shake256_inc_ctx_reset
  210 | #define __XOF_Init_x4 OQS_SHA3_shake256_x4_inc_init
  211 | #define __XOF_Update_x4 OQS_SHA3_shake256_x4_inc_absorb
  212 | #define __XOF_Final_x4 OQS_SHA3_shake256_x4_inc_finalize
  213 | #define __XOF_Squeeze_x4 OQS_SHA3_shake256_x4_inc_squeeze
  214 | #define __XOF_Release_x4 OQS_SHA3_shake256_x4_inc_ctx_release
  215 | #define __XOF_Reset_x4 OQS_SHA3_shake256_x4_inc_ctx_reset
  216 | /* === 256 bits security === */
  217 | #elif MQOM2_PARAM_SECURITY == 256
  218 | #define XOF_CTX_INIT_MAGIC 0xf00dbabebadfeeedULL
  219 | typedef struct {
  220 | 	uint64_t magic;
  221 | 	OQS_SHA3_shake256_inc_ctx ctx;
  222 | } Keccak_HashInstance;
  223 | #define XOF_CTX_X4_INIT_MAGIC 0xf11dbabebadf999dULL
  224 | typedef struct {
  225 | 	uint64_t magic;
  226 | 	OQS_SHA3_shake256_x4_inc_ctx ctx;
  227 | } Keccak_HashInstancetimes4;
  228 | #define __XOF_Init OQS_SHA3_shake256_inc_init
  229 | #define __XOF_Update OQS_SHA3_shake256_inc_absorb
  230 | #define __XOF_Final OQS_SHA3_shake256_inc_finalize
  231 | #define __XOF_Squeeze OQS_SHA3_shake256_inc_squeeze
  232 | #define __XOF_Release OQS_SHA3_shake256_inc_ctx_release
  233 | #define __XOF_Reset OQS_SHA3_shake256_inc_ctx_reset
  234 | #define __XOF_Init_x4 OQS_SHA3_shake256_x4_inc_init
  235 | #define __XOF_Update_x4 OQS_SHA3_shake256_x4_inc_absorb
  236 | #define __XOF_Final_x4 OQS_SHA3_shake256_x4_inc_finalize
  237 | #define __XOF_Squeeze_x4 OQS_SHA3_shake256_x4_inc_squeeze
  238 | #define __XOF_Release_x4 OQS_SHA3_shake256_x4_inc_ctx_release
  239 | #define __XOF_Reset_x4 OQS_SHA3_shake256_x4_inc_ctx_reset
  240 | #else
  241 | #error "No XOF implementation for this security level"
  242 | #endif
  243 |
  244 | /**/
  245 | static inline int _XOF_Init(Keccak_HashInstance *ctx) {
  246 | 	if (ctx == NULL) {
  247 | 		return -1;
  248 | 	}
  249 | 	if (ctx->magic == XOF_CTX_INIT_MAGIC) {
  250 | 		__XOF_Reset(&(ctx->ctx));
  251 | 	} else {
  252 | 		__XOF_Init(&(ctx->ctx));
  253 | 		ctx->magic = XOF_CTX_INIT_MAGIC;
  254 | 	}
  255 | 	return 0;
  256 | }
  257 | static inline int _XOF_Init_x4(Keccak_HashInstancetimes4 *ctx) {
  258 | 	if (ctx == NULL) {
  259 | 		return -1;
  260 | 	}
  261 | 	if (ctx->magic == XOF_CTX_X4_INIT_MAGIC) {
  262 | 		__XOF_Reset_x4(&(ctx->ctx));
  263 | 	} else {
  264 | 		__XOF_Init_x4(&(ctx->ctx));
  265 | 		ctx->magic = XOF_CTX_X4_INIT_MAGIC;
  266 | 	}
  267 | 	return 0;
  268 | }
  269 | /**/
  270 | static inline int _XOF_Update(Keccak_HashInstance *ctx, const uint8_t* data, size_t byte_len) {
  271 | 	if ((ctx == NULL) || (ctx->magic != XOF_CTX_INIT_MAGIC)) {
> 272 | 		return -1;
  273 | 	}
  274 | 	__XOF_Update(&(ctx->ctx), data, byte_len >> 3);
  275 | 	return 0;
  276 | }
  277 | static inline int _XOF_Update_x4(Keccak_HashInstancetimes4 *ctx, const uint8_t *data[4], size_t byte_len) {
  278 | 	if ((ctx == NULL) || (ctx->magic != XOF_CTX_X4_INIT_MAGIC)) {
  279 | 		return -1;
  280 | 	}
  281 | 	__XOF_Update_x4(&(ctx->ctx), data[0], data[1], data[2], data[3], byte_len >> 3);
  282 | 	return 0;
  283 | }
  284 | /**/
  285 | static inline int _XOF_Squeeze(Keccak_HashInstance *ctx, uint8_t* data, size_t byte_len) {
  286 | 	if ((ctx == NULL) || (ctx->magic != XOF_CTX_INIT_MAGIC)) {
  287 | 		return -1;
  288 | 	}
  289 | 	__XOF_Squeeze(data, byte_len >> 3, &(ctx->ctx));
  290 | 	return 0;
  291 | }
  292 | static inline int _XOF_Squeeze_x4(Keccak_HashInstancetimes4 *ctx, uint8_t *data[4], size_t byte_len) {
  293 | 	if ((ctx == NULL) || (ctx->magic != XOF_CTX_X4_INIT_MAGIC)) {
  294 | 		return -1;
  295 | 	}
  296 | 	__XOF_Squeeze_x4(data[0], data[1], data[2], data[3], byte_len >> 3, &(ctx->ctx));
  297 | 	return 0;
  298 | }
  299 | /**/
  300 | static inline int _XOF_Final(Keccak_HashInstance *ctx, const uint8_t* dummy) {
  301 | 	(void)dummy;
  302 | 	if ((ctx == NULL) || (ctx->magic != XOF_CTX_INIT_MAGIC)) {
  303 | 		return -1;
  304 | 	}
  305 | 	__XOF_Final(&(ctx->ctx));
  306 | 	return 0;
  307 | }
  308 | static inline int _XOF_Final_x4(Keccak_HashInstancetimes4 *ctx, const uint8_t* dummy) {
  309 | 	(void)dummy;
  310 | 	if ((ctx == NULL) || (ctx->magic != XOF_CTX_X4_INIT_MAGIC)) {
  311 | 		return -1;
  312 | 	}
  313 | 	__XOF_Final_x4(&(ctx->ctx));
  314 | 	return 0;
  315 | }
  316 |
  317 | static inline void _XOF_Release(Keccak_HashInstance *ctx) {
  318 | 	if ((ctx != NULL) && (ctx->magic == XOF_CTX_INIT_MAGIC)) {
  319 | 		__XOF_Release(&(ctx->ctx));
  320 | 	}
  321 | 	if(ctx != NULL){
  322 | 		ctx->magic = 0;
  323 | 	}
  324 | 	return;
  325 | }
  326 | static inline void _XOF_Release_x4(Keccak_HashInstancetimes4 *ctx) {
  327 | 	if ((ctx != NULL) && (ctx->magic == XOF_CTX_X4_INIT_MAGIC)) {
  328 | 		__XOF_Release_x4(&(ctx->ctx));
  329 | 	}
  330 | 	if(ctx != NULL){
  331 | 		ctx->magic = 0;
  332 | 	}
  333 | 	return;
  334 | }
  335 |
  336 | #endif
  337 |
  338 | /* Deal with namespacing */
  339 | #define xof_init MQOM_NAMESPACE(xof_init)
  340 | #define xof_update MQOM_NAMESPACE(xof_update)
  341 | #define xof_squeeze MQOM_NAMESPACE(xof_squeeze)
  342 | #define xof_clean_ctx MQOM_NAMESPACE(xof_clean_ctx)
  343 | #define xof_init_x4 MQOM_NAMESPACE(xof_init_x4)
  344 | #define xof_update_x4 MQOM_NAMESPACE(xof_update_x4)
  345 | #define xof_squeeze_x4 MQOM_NAMESPACE(xof_squeeze_x4)
  346 | #define xof_clean_ctx_x4 MQOM_NAMESPACE(xof_clean_ctx_x4)
  347 |
  348 | /* Hash and XOF contexts are simply Keccak instances, with XOF finalization state
  349 |  * for XOF
  350 |  */
  351 | typedef struct {
  352 | 	uint8_t xof_finalized;
  353 | 	Keccak_HashInstance ctx;
  354 | } xof_context;
  355 |
  356 | /* x4 (4 times) context */
  357 | typedef struct {
  358 | 	uint8_t xof_finalized;
  359 | 	Keccak_HashInstancetimes4 ctx;
  360 | } xof_context_x4;
  361 |
  362 | /* Exported API for XOF, simple and x4 */
  363 | int xof_init(xof_context *ctx);
  364 | int xof_update(xof_context *ctx, const uint8_t *data, size_t byte_len);
  365 | int xof_squeeze(xof_context *ctx, uint8_t *out, uint32_t byte_len);
  366 | void xof_clean_ctx(xof_context *ctx);
  367 |
  368 | int xof_init_x4(xof_context_x4 *ctx);
  369 | int xof_update_x4(xof_context_x4 *ctx, const uint8_t *data[4], size_t byte_len);
  370 | int xof_squeeze_x4(xof_context_x4 *ctx, uint8_t *out[4], uint32_t byte_len);
  371 | void xof_clean_ctx_x4(xof_context_x4 *ctx);
  372 |

Reach line at /src/liboqs/src/sig/mqom/mqom_mqom_common/xof.h:272 (observed count 0).


    1 | // SPDX-License-Identifier: MIT
    2 |
    3 | #include <stdlib.h>
    4 |
    5 | #include <oqs/sig_uov.h>
    6 |
    7 | #if defined(OQS_ENABLE_SIG_uov_ov_V_pkc)
    8 | OQS_SIG *OQS_SIG_uov_ov_V_pkc_new(void) {
    9 |
   10 | 	OQS_SIG *sig = OQS_MEM_malloc(sizeof(OQS_SIG));
   11 | 	if (sig == NULL) {
   12 | 		return NULL;
   13 | 	}
   14 | 	sig->method_name = OQS_SIG_alg_uov_ov_V_pkc;
   15 | 	sig->alg_version = "Round 2";
   16 |
   17 | 	sig->claimed_nist_level = 5;
   18 | 	sig->euf_cma = true;
   19 | 	sig->suf_cma = false;
   20 | 	sig->sig_with_ctx_support = false;
   21 |
   22 | 	sig->length_public_key = OQS_SIG_uov_ov_V_pkc_length_public_key;
   23 | 	sig->length_secret_key = OQS_SIG_uov_ov_V_pkc_length_secret_key;
   24 | 	sig->length_signature = OQS_SIG_uov_ov_V_pkc_length_signature;
   25 |
   26 | 	sig->keypair = OQS_SIG_uov_ov_V_pkc_keypair;
   27 | 	sig->sign = OQS_SIG_uov_ov_V_pkc_sign;
   28 | 	sig->verify = OQS_SIG_uov_ov_V_pkc_verify;
   29 | 	sig->sign_with_ctx_str = OQS_SIG_uov_ov_V_pkc_sign_with_ctx_str;
   30 | 	sig->verify_with_ctx_str = OQS_SIG_uov_ov_V_pkc_verify_with_ctx_str;
   31 |
   32 | 	return sig;
   33 | }
   34 |
   35 | extern int pqov_uov_V_pkc_ref_keypair(uint8_t *pk, uint8_t *sk);
   36 | extern int pqov_uov_V_pkc_ref_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
   37 | extern int pqov_uov_V_pkc_ref_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);
   38 |
   39 | #if defined(OQS_ENABLE_SIG_uov_ov_V_pkc_neon)
   40 | extern int pqov_uov_V_pkc_neon_keypair(uint8_t *pk, uint8_t *sk);
   41 | extern int pqov_uov_V_pkc_neon_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
   42 | extern int pqov_uov_V_pkc_neon_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);
   43 | #endif
   44 |
   45 | #if defined(OQS_ENABLE_SIG_uov_ov_V_pkc_avx2)
   46 | extern int pqov_uov_V_pkc_avx2_keypair(uint8_t *pk, uint8_t *sk);
   47 | extern int pqov_uov_V_pkc_avx2_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk);
   48 | extern int pqov_uov_V_pkc_avx2_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk);
   49 | #endif
   50 |
   51 | OQS_API OQS_STATUS OQS_SIG_uov_ov_V_pkc_keypair(uint8_t *public_key, uint8_t *secret_key) {
   52 | #if defined(OQS_ENABLE_SIG_uov_ov_V_pkc_neon)
   53 | #if defined(OQS_DIST_BUILD)
   54 | 	if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) {
   55 | #endif /* OQS_DIST_BUILD */
   56 | 		return (OQS_STATUS) pqov_uov_V_pkc_neon_keypair(public_key, secret_key);
   57 | #if defined(OQS_DIST_BUILD)
   58 | 	} else {
   59 | 		return (OQS_STATUS) pqov_uov_V_pkc_ref_keypair(public_key, secret_key);
   60 | 	}
   61 | #endif /* OQS_DIST_BUILD */
   62 | #elif defined(OQS_ENABLE_SIG_uov_ov_V_pkc_avx2)
   63 | #if defined(OQS_DIST_BUILD)
   64 | 	if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
   65 | #endif /* OQS_DIST_BUILD */
   66 | 		return (OQS_STATUS) pqov_uov_V_pkc_avx2_keypair(public_key, secret_key);
   67 | #if defined(OQS_DIST_BUILD)
   68 | 	} else {
   69 | 		return (OQS_STATUS) pqov_uov_V_pkc_ref_keypair(public_key, secret_key);
   70 | 	}
   71 | #endif /* OQS_DIST_BUILD */
   72 | #else
   73 | 	return (OQS_STATUS) pqov_uov_V_pkc_ref_keypair(public_key, secret_key);
   74 | #endif
   75 | }
   76 |
   77 | OQS_API OQS_STATUS OQS_SIG_uov_ov_V_pkc_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) {
   78 | #if defined(OQS_ENABLE_SIG_uov_ov_V_pkc_neon)
   79 | #if defined(OQS_DIST_BUILD)
   80 | 	if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) {
   81 | #endif /* OQS_DIST_BUILD */
   82 | 		return (OQS_STATUS) pqov_uov_V_pkc_neon_signature(signature, signature_len, message, message_len, secret_key);
   83 | #if defined(OQS_DIST_BUILD)
   84 | 	} else {
   85 | 		return (OQS_STATUS) pqov_uov_V_pkc_ref_signature(signature, signature_len, message, message_len, secret_key);
   86 | 	}
   87 | #endif /* OQS_DIST_BUILD */
   88 | #elif defined(OQS_ENABLE_SIG_uov_ov_V_pkc_avx2)
   89 | #if defined(OQS_DIST_BUILD)
   90 | 	if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
   91 | #endif /* OQS_DIST_BUILD */
   92 | 		return (OQS_STATUS) pqov_uov_V_pkc_avx2_signature(signature, signature_len, message, message_len, secret_key);
   93 | #if defined(OQS_DIST_BUILD)
   94 | 	} else {
>  95 | 		return (OQS_STATUS) pqov_uov_V_pkc_ref_signature(signature, signature_len, message, message_len, secret_key);
   96 | 	}
   97 | #endif /* OQS_DIST_BUILD */
   98 | #else
   99 | 	return (OQS_STATUS) pqov_uov_V_pkc_ref_signature(signature, signature_len, message, message_len, secret_key);
  100 | #endif
  101 | }
  102 |
  103 | OQS_API OQS_STATUS OQS_SIG_uov_ov_V_pkc_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) {
  104 | #if defined(OQS_ENABLE_SIG_uov_ov_V_pkc_neon)
  105 | #if defined(OQS_DIST_BUILD)
  106 | 	if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) {
  107 | #endif /* OQS_DIST_BUILD */
  108 | 		return (OQS_STATUS) pqov_uov_V_pkc_neon_verify(signature, signature_len, message, message_len, public_key);
  109 | #if defined(OQS_DIST_BUILD)
  110 | 	} else {
  111 | 		return (OQS_STATUS) pqov_uov_V_pkc_ref_verify(signature, signature_len, message, message_len, public_key);
  112 | 	}
  113 | #endif /* OQS_DIST_BUILD */
  114 | #elif defined(OQS_ENABLE_SIG_uov_ov_V_pkc_avx2)
  115 | #if defined(OQS_DIST_BUILD)
  116 | 	if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2)) {
  117 | #endif /* OQS_DIST_BUILD */
  118 | 		return (OQS_STATUS) pqov_uov_V_pkc_avx2_verify(signature, signature_len, message, message_len, public_key);
  119 | #if defined(OQS_DIST_BUILD)
  120 | 	} else {
  121 | 		return (OQS_STATUS) pqov_uov_V_pkc_ref_verify(signature, signature_len, message, message_len, public_key);
  122 | 	}
  123 | #endif /* OQS_DIST_BUILD */
  124 | #else
  125 | 	return (OQS_STATUS) pqov_uov_V_pkc_ref_verify(signature, signature_len, message, message_len, public_key);
  126 | #endif
  127 | }
  128 |
  129 | OQS_API OQS_STATUS OQS_SIG_uov_ov_V_pkc_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *secret_key) {
  130 | 	if (ctx_str == NULL && ctx_str_len == 0) {
  131 | 		return OQS_SIG_uov_ov_V_pkc_sign(signature, signature_len, message, message_len, secret_key);
  132 | 	} else {
  133 | 		return OQS_ERROR;
  134 | 	}
  135 | }
  136 |
  137 | OQS_API OQS_STATUS OQS_SIG_uov_ov_V_pkc_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *public_key) {
  138 | 	if (ctx_str == NULL && ctx_str_len == 0) {
  139 | 		return OQS_SIG_uov_ov_V_pkc_verify(message, message_len, signature, signature_len, public_key);
  140 | 	} else {
  141 | 		return OQS_ERROR;
  142 | 	}
  143 | }
  144 | #endif

Reach line at /src/liboqs/src/sig/uov/sig_uov_ov_V_pkc.c:95 (observed count 0).


    1 | /*
    2 |   This file is for public-key generation
    3 | */
    4 |
    5 | #include <assert.h>
    6 | #include <stdint.h>
    7 | #include <stdio.h>
    8 | #include <string.h>
    9 |
   10 | #include "controlbits.h"
   11 | #include "benes.h"
   12 | #include "crypto_declassify.h"
   13 | #include "crypto_uint64.h"
   14 | #include "params.h"
   15 | #include "pk_gen.h"
   16 | #include "root.h"
   17 | #include "uint64_sort.h"
   18 | #include "util.h"
   19 |
   20 | static crypto_uint64 uint64_is_equal_declassify(uint64_t t, uint64_t u) {
   21 |     crypto_uint64 mask = crypto_uint64_equal_mask(t, u);
   22 |     crypto_declassify(&mask, sizeof mask);
   23 |     return mask;
   24 | }
   25 |
   26 | static crypto_uint64 uint64_is_zero_declassify(uint64_t t) {
   27 |     crypto_uint64 mask = crypto_uint64_zero_mask(t);
   28 |     crypto_declassify(&mask, sizeof mask);
   29 |     return mask;
   30 | }
   31 |
   32 | #define min(a, b) (((a) < (b)) ? (a) : (b))
   33 |
   34 | /* return number of trailing zeros of the non-zero input in */
   35 | static inline int ctz(uint64_t in) {
   36 |     int i, b, m = 0, r = 0;
   37 |
   38 |     for (i = 0; i < 64; i++) {
   39 |         b = (in >> i) & 1;
   40 |         m |= b;
   41 |         r += (m ^ 1) & (b ^ 1);
   42 |     }
   43 |
   44 |     return r;
   45 | }
   46 |
   47 | static inline uint64_t same_mask(uint16_t x, uint16_t y) {
   48 |     uint64_t mask;
   49 |
   50 |     mask = x ^ y;
   51 |     mask -= 1;
   52 |     mask >>= 63;
   53 |     mask = -mask;
   54 |
   55 |     return mask;
   56 | }
   57 |
   58 | static int mov_columns(uint8_t mat[][ SYS_N / 8 ], int16_t *pi, uint64_t *pivots) {
   59 |     int i, j, k, s, block_idx, row;
   60 |     uint64_t buf[64], ctz_list[32], t, d, mask, one = 1;
   61 |
   62 |     row = PK_NROWS - 32;
   63 |     block_idx = row / 8;
   64 |
   65 |     // extract the 32x64 matrix
   66 |
   67 |     for (i = 0; i < 32; i++) {
   68 |         buf[i] = load8( &mat[ row + i ][ block_idx ] );
   69 |     }
   70 |
   71 |     // compute the column indices of pivots by Gaussian elimination.
   72 |     // the indices are stored in ctz_list
   73 |
   74 |     *pivots = 0;
   75 |
   76 |     for (i = 0; i < 32; i++) {
   77 |         t = buf[i];
   78 |         for (j = i + 1; j < 32; j++) {
   79 |             t |= buf[j];
   80 |         }
   81 |
   82 |         if (uint64_is_zero_declassify(t)) {
>  83 |             return -1;    // return if buf is not full rank
   84 |         }
   85 |
   86 |         ctz_list[i] = s = ctz(t);
   87 |         *pivots |= one << ctz_list[i];
   88 |
   89 |         for (j = i + 1; j < 32; j++) {
   90 |             mask = (buf[i] >> s) & 1;
   91 |             mask -= 1;
   92 |             buf[i] ^= buf[j] & mask;
   93 |         }
   94 |         for (j = i + 1; j < 32; j++) {
   95 |             mask = (buf[j] >> s) & 1;
   96 |             mask = -mask;
   97 |             buf[j] ^= buf[i] & mask;
   98 |         }
   99 |     }
  100 |
  101 |     // updating permutation
  102 |
  103 |     for (j = 0;   j < 32; j++) {
  104 |         for (k = j + 1; k < 64; k++) {
  105 |             d = pi[ row + j ] ^ pi[ row + k ];
  106 |             d &= same_mask((uint16_t)k, (uint16_t)ctz_list[j]);
  107 |             pi[ row + j ] ^= d;
  108 |             pi[ row + k ] ^= d;
  109 |         }
  110 |     }
  111 |
  112 |     // moving columns of mat according to the column indices of pivots
  113 |
  114 |     for (i = 0; i < PK_NROWS; i++) {
  115 |         t = load8( &mat[ i ][ block_idx ] );
  116 |
  117 |         for (j = 0; j < 32; j++) {
  118 |             d  = t >> j;
  119 |             d ^= t >> ctz_list[j];
  120 |             d &= 1;
  121 |
  122 |             t ^= d << ctz_list[j];
  123 |             t ^= d << j;
  124 |         }
  125 |
  126 |         store8( &mat[ i ][ block_idx ], t );
  127 |     }
  128 |
  129 |     return 0;
  130 | }
  131 |
  132 | /* input: secret key sk */
  133 | /* output: public key pk */
  134 | int pk_gen(unsigned char *pk, unsigned char *sk, const uint32_t *perm, int16_t *pi, uint64_t *pivots) {
  135 |     int i, j, k;
  136 |     int row, c;
  137 |
  138 |     uint64_t buf[ 1 << GFBITS ];
  139 |
  140 |     unsigned char mat[ PK_NROWS ][ SYS_N / 8 ];
  141 |     unsigned char mask;
  142 |     unsigned char b;
  143 |
  144 |     gf g[ SYS_T + 1 ]; // Goppa polynomial
  145 |     gf L[ SYS_N ]; // support
  146 |     gf inv[ SYS_N ];
  147 |
  148 |     //
  149 |
  150 |     g[ SYS_T ] = 1;
  151 |
  152 |     for (i = 0; i < SYS_T; i++) {
  153 |         g[i] = load_gf(sk);
  154 |         sk += 2;
  155 |     }
  156 |
  157 |     for (i = 0; i < (1 << GFBITS); i++) {
  158 |         buf[i] = perm[i];
  159 |         buf[i] <<= 31;
  160 |         buf[i] |= i;
  161 |     }
  162 |
  163 |     uint64_sort(buf, 1 << GFBITS);
  164 |
  165 |     for (i = 1; i < (1 << GFBITS); i++) {
  166 |         if (uint64_is_equal_declassify(buf[i - 1] >> 31, buf[i] >> 31)) {
  167 |             return -1;
  168 |         }
  169 |     }
  170 |
  171 |     for (i = 0; i < (1 << GFBITS); i++) {
  172 |         pi[i] = buf[i] & GFMASK;
  173 |     }
  174 |     for (i = 0; i < SYS_N;         i++) {
  175 |         L[i] = bitrev(pi[i]);
  176 |     }
  177 |
  178 |     // filling the matrix
  179 |
  180 |     root(inv, g, L);
  181 |
  182 |     for (i = 0; i < SYS_N; i++) {
  183 |         inv[i] = gf_inv(inv[i]);

Reach line at /src/liboqs/src/kem/classic_mceliece/pqclean_mceliece348864f_clean/pk_gen.c:83 (observed count 0).


    1 | /*
    2 |  * Copyright (c) The mldsa-native project authors
    3 |  * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
    4 |  */
    5 |
    6 | /* References
    7 |  * ==========
    8 |  *
    9 |  * - [REF_AVX2]
   10 |  *   CRYSTALS-Dilithium optimized AVX2 implementation
   11 |  *   Bai, Ducas, Kiltz, Lepoint, Lyubashevsky, Schwabe, Seiler, Stehlé
   12 |  *   https://github.com/pq-crystals/dilithium/tree/master/avx2
   13 |  */
   14 |
   15 | /*
   16 |  * This file is derived from the public domain
   17 |  * AVX2 Dilithium implementation @[REF_AVX2].
   18 |  */
   19 |
   20 | #include "../../../common.h"
   21 |
   22 | #if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && \
   23 |     !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) && \
   24 |     (defined(MLD_CONFIG_MULTILEVEL_WITH_SHARED) || MLDSA_ETA == 2)
   25 |
   26 | #include <immintrin.h>
   27 | #include "arith_native_x86_64.h"
   28 | #include "consts.h"
   29 |
   30 | #define MLD_AVX2_ETA2 2
   31 |
   32 | /*
   33 |  * Reference: In the pqcrystals implementation this function is called
   34 |  *            rej_eta_avx and supports multiple values for ETA via preprocessor
   35 |  *            conditionals. We move the conditionals to the frontend.
   36 |  */
   37 | unsigned int mld_rej_uniform_eta2_avx2(
   38 |     int32_t *MLD_RESTRICT r,
   39 |     const uint8_t buf[MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN])
   40 | {
   41 |   unsigned int ctr, pos;
   42 |   uint32_t good;
   43 |   __m256i f0, f1, f2;
   44 |   __m128i g0, g1;
   45 |   const __m256i mask = _mm256_set1_epi8(15);
   46 |   const __m256i eta = _mm256_set1_epi8(MLD_AVX2_ETA2);
   47 |   const __m256i bound = mask;
   48 |   /* check-magic: -6560 ==  32*round(-2**10 / 5) */
   49 |   const __m256i v = _mm256_set1_epi32(-6560);
   50 |   const __m256i p = _mm256_set1_epi32(5);
   51 |
   52 |   ctr = pos = 0;
   53 |   while (ctr <= MLDSA_N - 8 && pos <= MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN - 16)
   54 |   {
   55 |     f0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((__m128i *)&buf[pos]));
   56 |     f1 = _mm256_slli_epi16(f0, 4);
   57 |     f0 = _mm256_or_si256(f0, f1);
   58 |     f0 = _mm256_and_si256(f0, mask);
   59 |
   60 |     f1 = _mm256_sub_epi8(f0, bound);
   61 |     f0 = _mm256_sub_epi8(eta, f0);
   62 |     good = (uint32_t)_mm256_movemask_epi8(f1);
   63 |
   64 |     g0 = _mm256_castsi256_si128(f0);
   65 |     g1 = _mm_loadl_epi64((__m128i *)&mld_rej_uniform_table[good & 0xFF]);
   66 |     g1 = _mm_shuffle_epi8(g0, g1);
   67 |     f1 = _mm256_cvtepi8_epi32(g1);
   68 |     f2 = _mm256_mulhrs_epi16(f1, v);
   69 |     f2 = _mm256_mullo_epi16(f2, p);
   70 |     f1 = _mm256_add_epi32(f1, f2);
   71 |     _mm256_storeu_si256((__m256i *)&r[ctr], f1);
   72 |     ctr += (unsigned)_mm_popcnt_u32(good & 0xFF);
   73 |     good >>= 8;
   74 |     pos += 4;
   75 |
   76 |     if (ctr > MLDSA_N - 8)
   77 |     {
   78 |       break;
   79 |     }
   80 |     g0 = _mm_bsrli_si128(g0, 8);
   81 |     g1 = _mm_loadl_epi64((__m128i *)&mld_rej_uniform_table[good & 0xFF]);
   82 |     g1 = _mm_shuffle_epi8(g0, g1);
   83 |     f1 = _mm256_cvtepi8_epi32(g1);
   84 |     f2 = _mm256_mulhrs_epi16(f1, v);
   85 |     f2 = _mm256_mullo_epi16(f2, p);
   86 |     f1 = _mm256_add_epi32(f1, f2);
   87 |     _mm256_storeu_si256((__m256i *)&r[ctr], f1);
   88 |     ctr += (unsigned)_mm_popcnt_u32(good & 0xFF);
   89 |     good >>= 8;
   90 |     pos += 4;
   91 |
   92 |     if (ctr > MLDSA_N - 8)
   93 |     {
>  94 |       break;
   95 |     }
   96 |     g0 = _mm256_extracti128_si256(f0, 1);
   97 |     g1 = _mm_loadl_epi64((__m128i *)&mld_rej_uniform_table[good & 0xFF]);
   98 |     g1 = _mm_shuffle_epi8(g0, g1);
   99 |     f1 = _mm256_cvtepi8_epi32(g1);
  100 |     f2 = _mm256_mulhrs_epi16(f1, v);
  101 |     f2 = _mm256_mullo_epi16(f2, p);
  102 |     f1 = _mm256_add_epi32(f1, f2);
  103 |     _mm256_storeu_si256((__m256i *)&r[ctr], f1);
  104 |     ctr += (unsigned)_mm_popcnt_u32(good & 0xFF);
  105 |     good >>= 8;
  106 |     pos += 4;
  107 |
  108 |     if (ctr > MLDSA_N - 8)
  109 |     {
  110 |       break;
  111 |     }
  112 |     g0 = _mm_bsrli_si128(g0, 8);
  113 |     g1 = _mm_loadl_epi64((__m128i *)&mld_rej_uniform_table[good]);
  114 |     g1 = _mm_shuffle_epi8(g0, g1);
  115 |     f1 = _mm256_cvtepi8_epi32(g1);
  116 |     f2 = _mm256_mulhrs_epi16(f1, v);
  117 |     f2 = _mm256_mullo_epi16(f2, p);
  118 |     f1 = _mm256_add_epi32(f1, f2);
  119 |     _mm256_storeu_si256((__m256i *)&r[ctr], f1);
  120 |     ctr += (unsigned)_mm_popcnt_u32(good);
  121 |     pos += 4;
  122 |   }
  123 |
  124 |   while (ctr < MLDSA_N && pos < MLD_AVX2_REJ_UNIFORM_ETA2_BUFLEN)
  125 |   {
  126 |     uint32_t t0 = buf[pos] & 0x0F;
  127 |     uint32_t t1 = buf[pos++] >> 4;
  128 |
  129 |     if (t0 < 15)
  130 |     {
  131 |       t0 = t0 - (205 * t0 >> 10) * 5;
  132 |       r[ctr++] = (int32_t)(2 - t0);
  133 |     }
  134 |     if (t1 < 15 && ctr < MLDSA_N)
  135 |     {
  136 |       t1 = t1 - (205 * t1 >> 10) * 5;
  137 |       r[ctr++] = (int32_t)(2 - t1);
  138 |     }
  139 |   }
  140 |
  141 |   return ctr;
  142 | }
  143 |
  144 | #else /* MLD_ARITH_BACKEND_X86_64_DEFAULT && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
  145 |          && (MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 2) */
  146 |
  147 | MLD_EMPTY_CU(avx2_rej_uniform_eta2)
  148 |
  149 | #endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \
  150 |           !MLD_CONFIG_MULTILEVEL_NO_SHARED &&   \
  151 |           (MLD_CONFIG_MULTILEVEL_WITH_SHARED || MLDSA_ETA == 2)) */
  152 |
  153 | /* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
  154 |  * Don't modify by hand -- this is auto-generated by scripts/autogen. */
  155 | #undef MLD_AVX2_ETA2

Reach line at /src/liboqs/src/sig/ml_dsa/mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c:94 (observed count 0).


    1 | // SPDX-License-Identifier: MIT
    2 |
    3 | #include <stdlib.h>
    4 |
    5 | #include "../../sig_slh_dsa.h"
    6 | #include "../../slh_dsa_c/slh_dsa.h"
    7 | #include "../../slh_dsa_c/slh_prehash.h"
    8 | #include <oqs/oqs.h>
    9 |
   10 |
   11 | #if defined(OQS_ENABLE_SIG_slh_dsa_sha3_256_prehash_shake_256s)
   12 | OQS_SIG *OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_new(void) {
   13 |
   14 | 	OQS_SIG *sig = OQS_MEM_malloc(sizeof(OQS_SIG));
   15 | 	if(sig == NULL) {
>  16 | 		return NULL;
   17 | 	}
   18 | 	sig->method_name = OQS_SIG_alg_slh_dsa_sha3_256_prehash_shake_256s;
   19 | 	sig->alg_version = "FIPS205";
   20 |
   21 | 	sig->claimed_nist_level = 5;
   22 | 	sig->euf_cma = true;
   23 | 	sig->suf_cma = false;
   24 | 	sig->sig_with_ctx_support = true;
   25 |
   26 | 	sig->length_public_key = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_length_public_key;
   27 | 	sig->length_secret_key = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_length_secret_key;
   28 | 	sig->length_signature = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_length_signature;
   29 |
   30 | 	sig->keypair = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_keypair;
   31 | 	sig->sign = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_sign;
   32 | 	sig->verify = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_verify;
   33 | 	sig->sign_with_ctx_str = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_sign_with_ctx_str;
   34 | 	sig->verify_with_ctx_str = OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_verify_with_ctx_str;
   35 |
   36 | 	return sig;
   37 | }
   38 |
   39 | static int slh_randombytes(uint8_t *x, size_t xlen) {
   40 |
   41 | 	OQS_randombytes(x, xlen);
   42 | 	return OQS_SUCCESS;
   43 | }
   44 |
   45 | OQS_API OQS_STATUS OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_keypair(uint8_t *public_key, uint8_t *secret_key) {
   46 |
   47 | 	const slh_param_t *prm = &slh_dsa_shake_256s;
   48 | 	int(*rbg)(uint8_t *x, size_t xlen) = slh_randombytes;
   49 | 	return slh_keygen(secret_key, public_key, rbg, prm);
   50 | }
   51 |
   52 | OQS_API OQS_STATUS OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_sign(uint8_t *signature,
   53 | 	size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) {
   54 |
   55 | 	const slh_param_t *prm = &slh_dsa_shake_256s;
   56 |
   57 | 	const char *ph = "SHA3-256";
   58 | 	const uint8_t *ctx_str = NULL;
   59 | 	const size_t ctx_str_len = 0;
   60 | 	uint8_t addrnd[32];
   61 | 	OQS_randombytes(addrnd, 32);
   62 |
   63 | 	*signature_len = hash_slh_sign(signature, message, message_len, ctx_str,
   64 | 		ctx_str_len, ph, secret_key, addrnd, prm);
   65 |
   66 | 	if(*signature_len == 0) {
   67 | 		return OQS_ERROR;
   68 | 	}
   69 | 	return OQS_SUCCESS;
   70 | }
   71 |
   72 | OQS_API OQS_STATUS OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_verify(const uint8_t *message,
   73 | 	size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) {
   74 |
   75 | 	const slh_param_t *prm = &slh_dsa_shake_256s;
   76 | 	const char *ph = "SHA3-256";
   77 | 	const uint8_t *ctx_str = NULL;
   78 | 	const size_t ctx_str_len = 0;
   79 |
   80 | 	int res = hash_slh_verify(message, message_len, signature, signature_len,
   81 | 		ctx_str, ctx_str_len, ph, public_key, prm);
   82 |
   83 | 	if(res == 0) {
   84 | 		return OQS_ERROR;
   85 | 	}
   86 | 	return OQS_SUCCESS;
   87 | }
   88 |
   89 | OQS_API OQS_STATUS OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_sign_with_ctx_str(uint8_t *signature,
   90 | 	size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str,
   91 | 	size_t ctx_str_len, const uint8_t *secret_key) {
   92 |
   93 | 	const slh_param_t *prm = &slh_dsa_shake_256s;
   94 | 	const char *ph = "SHA3-256";
   95 | 	uint8_t addrnd[32];
   96 | 	OQS_randombytes(addrnd, 32);
   97 |
   98 | 	*signature_len = hash_slh_sign(signature, message, message_len, ctx_str,
   99 | 		ctx_str_len, ph, secret_key, addrnd, prm);
  100 |
  101 | 	if(*signature_len == 0) {
  102 | 		return OQS_ERROR;
  103 | 	}
  104 | 	return OQS_SUCCESS;
  105 | }
  106 |
  107 | OQS_API OQS_STATUS OQS_SIG_slh_dsa_sha3_256_prehash_shake_256s_verify_with_ctx_str(const uint8_t *message,
  108 | 	size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str,
  109 | 	size_t ctx_str_len, const uint8_t *public_key) {
  110 |
  111 | 	const slh_param_t *prm = &slh_dsa_shake_256s;
  112 | 	const char *ph = "SHA3-256";
  113 | 	int res = hash_slh_verify(message, message_len, signature, signature_len,
  114 | 		ctx_str, ctx_str_len, ph, public_key, prm);
  115 |
  116 |    if(res == 0) {

Reach line at /src/liboqs/src/sig/slh_dsa/wrappers/prehash_sha3_256/slh_dsa_sha3_256_prehash_shake_256s.c:16 (observed count 0).