This can be easily done using VABS, a general-purpose cross-sectional analysis tool. VABS obtain the mass and stiffness matrix for E-B or Timoshenko model without the associated assumptions. The tool can be launched in the cloud at https://cdmhub.org/resources/vabs
If you introduce assumptions, it is pretty easy. If you don't introduce assumptions, analytical solutions exist for a few simple beams. See my lecture notes at https://cdmhub.org/resources/381 and the paper Yu, W. and Hodges, D. H.: “Elasticity Solutions versus Asymptotic Sectional Analysis of Homogeneous, Isotropic, Prismatic Beams,” Journal of Applied Mechanics, vol. 71, no. 1, 2004, pp. 15-23.
Are you talking about how to compute EA, EI, GJ, kGA, etc or you are talking about that the mass/stiffness matrix for the 1D beam finite element code? My answer was for the former question. For the latter, it depends on number of nodes for the 1D element and corresponding shape functions. Please refer to https://www.researchgate.net/publication/306418160_A_novel_approach_to_analyze_beam-like_composite_structures_using_mechanics_of_structure_genome.
Note, I prefer to not call a beam model as 3D beam. A beam model is a 1D model, the fundamental variable is beam reference line, although it could represent displacements in three directions (three displacements and one rotation for E-B model, and three displacements and three rotations for Timoshenko model). Please refer to my article on dimensionality of models at https://cdmhub.org/blog/2015/10/on-dimensionality-of-models.
Article A novel approach to analyze beam-like composite structures u...